1 条题解
-
0
#include <cctype> #include <cstdio> #include <algorithm> using namespace std; int n, m, t, ans; struct node { int p, x; } milk[2000005]; inline int read() { // 快读 int n = 0; char ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) { n = (n << 3) + (n << 1) + (ch - 48); ch = getchar(); } return n; } bool cmp(node a, node b) { // 贪心,按单价升序排序 return a.p < b.p; } int main() { freopen("milk.in", "r", stdin); freopen("milk.out", "w", stdout); // 文件输入输出 n = read(), m = read(); for (int i = 0; i < m; i++) milk[i].p = read(), milk[i].x = read(); sort(milk, milk + m, cmp); // 排序 for (int i = 0; i < m && n > 0; i++) { if (n >= milk[i].x) t = milk[i].x, n -= t; else t = n, n = 0; ans += t * milk[i].p; } printf("%d", ans); return 0; }
- 1
信息
- ID
- 179
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 6
- 标签
- (无)
- 递交数
- 105
- 已通过
- 33
- 上传者