[Codeforces] 1015C. Songs Compression
題目URL: http://codeforces.com/contest/1015/problem/C
相減sort後,aa總和從小減到大一邊記數,比b小就輸出
相減sort後,aa總和從小減到大一邊記數,比b小就輸出
#include<bits/stdc++.h> using namespace std; #define int long long int aa,bb,str[100005]; signed main() { int a,b,total=0,totala=0,tot=0; cin >> a >> b; for(int i=0;i<a;i++) { cin >> aa >> bb;
str[i]=aa-bb;
total+=bb;
totala+=aa;
} sort(str,str+a); if(total>b) cout << -1 << endl;
else {
for(int i=a-1;i>=0;i--)
{
//cout << str[i] << endl;
if(totala<=b)
break;
totala-=str[i];
tot++;
}
cout << tot << endl;
} return 0; }
留言
張貼留言