MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

Codeforces_problems/Songs Compression/solution.cpp:4–33  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2using namespace std;
3
4int main(){
5 long long int n, m, x=0, y=0, aux=0, con=0;
6 cin >> n >> m;
7 long long int a[n], b[n], c[n];
8 for(int i=0; i<n; i++){
9 cin >> a[i] >> b[i];
10 x+=a[i]; //x=total song size initially
11 y+=b[i]; //y=total song size after compression
12 
13 c[i]=a[i]-b[i]; //difference in music size after compression and initially
14 }
15
16 if(y>m){
17 cout << "-1";
18 return 0;
19 }
20 else{
21 sort(c, c+n); //Put the difference in ascending order
22 n--;
23 while(x>m){
24 x-=c[n];
25 n--;
26 con++;
27 }
28 }
29
30 cout << con;
31
32 return 0;
33}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected