#include<stdio.h> #include<algorithm> using namespace std; struct st { int k, a, b; bool operator<(st i) const { return abs(a - b) > abs(i.a - i.b); } }s[1000]; int n, a, b, res; void f1(int i) { int t = min(a, s[i].k); res += t*s[i].a; a -= t; s[i].k -= t; } void f2(int i) { int t = min(b, s[i].k); res += t*s[i].b; b -= t; s[i].k -= t; } int main() { for (;;) { scanf("%d %d %d", &n, &a, &b); if (!n) break; for (int i = 0; i < n; i++) scanf("%d %d %d", &s[i].k, &s[i].a, &s[i].b); sort(s, s + n); res = 0; for (int i = 0; i < n; i++) if (s[i].a < s[i].b) f1(i), f2(i); else f2(i), f1(i); printf("%d\n", res); } return 0; }
4716번: 풍선
https://www.acmicpc.net/problem/4716
피드 구독하기:
댓글
(
Atom
)
댓글 없음 :
댓글 쓰기