结构体排序 + tanxin 水题
/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
int amount, n, res;
struct M
{
int p, v;
bool operator < (const M& t) {
if(p != t.p) return p < t.p;
return v < t.v;
}
};
M m[5000 + 24];
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
res = 0;
scanf("%d%d", &amount, &n);
for(int i = 0; i < n; i++) {
scanf("%d%d", &m[i].p, &m[i].v);
}
sort(m, m + n);
// for(int i = 0; i < n; i++) cout << m[i].p << " " << m[i].v << "\n";
for(int i = 0; i < n && amount; i++) {
if(m[i].v > amount) { res += m[i].p * amount; amount = 0;}
else {amount -= m[i].v; res += m[i].p * m[i].v;}
}
printf("%d\n", res);
return 0;
}
/**/
先开始检验样例没有过,因为我把res的计算放在了amount置0的后面。鬼知道我在想什么。。。。