3709: [PA2014]Bohater 贪心

 1 #include<cstdio>
2 #include<iostream>
3 #include<algorithm>
4 #include<queue>
5 #define rep(i,j,k) for(register int i = j; i <= k; i++)
6 #define maxn 102333
7 #define ll long long
8 using namespace std;
9
11     int s = 0, t = 1; char c = getchar();
12     while( !isdigit(c) ) { if( c == '-' ) t = -1; c = getchar(); }
13     while( isdigit(c) ) s = s * 10 + c - 48, c = getchar();
14     return s * t;
15 }
16
17 struct node{ int d, a, t; } nod1[maxn], nod2[maxn];
18 bool cmp1(node a,node b) { return a.d < b.d; }
19 bool cmp2(node a,node b) { return a.a > b.a; }
20 int ans[maxn], top = 0;
21 int main() {
23     int d, a, s1 = 0, s2 = 0;
24     rep(i,1,n) {
26         if( d > a ) {
27             nod2[++s2].d = d, nod2[s2].a = a, nod2[s2].t = i;
28         } else {
29             nod1[++s1].d = d, nod1[s1].a = a, nod1[s1].t = i;
30         }
31     }
32     sort(nod1+1,nod1+1+s1,cmp1);
33     sort(nod2+1,nod2+1+s2,cmp2);
34     rep(i,1,s1) {
35         if( z > nod1[i].d ) {
36             ans[++top] = nod1[i].t;
37             z += nod1[i].a - nod1[i].d;
38         } else {
39             puts("NIE"); return 0;
40         }
41     }
42     rep(i,1,s2) {
43         if( z > nod2[i].d ) {
44             ans[++top] = nod2[i].t;
45             z += nod2[i].a - nod2[i].d;
46         } else {
47             puts("NIE"); return 0;
48         }
49     }
50     puts("TAK");
51     rep(i,1,n) if( i != n ) printf("%d ", ans[i]); else printf("%d\n", ans[i]);
52     return 0;
53 }

posted on 2016-05-09 19:53  83131  阅读(163)  评论(0编辑  收藏  举报