【BZOJ3709】【PA2014】Bohater

【题目链接】

【思路要点】

  • 补档博客,无题解。

【代码】

#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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值