您的位置:首页 > 其它

【BZOJ3709】【PA2014】Bohater

2018-03-22 13:38 253 查看
【题目链接】
点击打开链接

【思路要点】
补档博客,无题解。
【代码】
#include<bits/stdc++.h>
using namespace std;
#define MAXN	100005
struct info {long long cost, value; int home; };
int n, sa, sb, ans[MAXN], point;
info a[MAXN], b[MAXN];
long long sx, sy, value, tmp;
bool cmp (info x, info y) {
return x.cost < y.cost;
}
bool fail() {
sort(a + 1, a + sa + 1, cmp);
for (int i = 1; i <= sa; i++) {
ans[i] = a[i].home;
if (a[i].cost >= value) return true;
value += a[i].value - a[i].cost;
}
point = n; value = tmp;
sort(b + 1, b + sb + 1, cmp);
for (int i = 1; i <= sb; i++) {
ans[point--] = b[i].home;
if (b[i].cost >= value) return true;
value += b[i].value - b[i].cost;
}
printf("TAK\n");
for (int i = 1; i <= n; i++)
printf("%d ", ans[i]);
printf("\n");
return false;
}
int main() {
scanf("%d%lld", &n, &value);
for (int i = 1; i <= n; i++) {
long long x, y;
scanf("%lld%lld", &x, &y);
sx += x; sy += y;
if (x <= y) a[++sa] = (info) {x, y, i};
else b[++sb] = (info) {y, x, i};
}
if (sx > sy + value) {
printf("NIE\n");
return 0;
}
tmp = sy + value - sx;
if (fail()) printf("NIE\n");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: