标签:+= const printf script tput 贪心 ott sam ane
http://acm.hdu.edu.cn/showproblem.php?pid=2111
代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
struct goods {
int val;
int wei;
}s[maxn];
bool cmp(const goods& a, const goods& b) {
return a.val > b.val;
}
int main() {
int v, n;
while(~scanf("%d", &v)) {
if(v == 0)
break;
scanf("%d", &n);
for(int i = 1; i <= n; i ++)
scanf("%d %d", &s[i].val, &s[i].wei);
sort(s + 1, s + 1 + n, cmp);
int out = 0;
for(int i = 1; i <= n; i ++) {
while(s[i].wei != 0 && v != 0) {
out += s[i].val;
v--;
s[i].wei--;
}
}
printf("%d\n", out);
}
return 0;
}
标签:+= const printf script tput 贪心 ott sam ane
原文地址:https://www.cnblogs.com/zlrrrr/p/9451379.html