#include<stdio.h> #include<algorithm> #define st first #define nd second using namespace std; bool comp(pair<pair<int,int>,int> a,pair<pair<int,int>,int> b){ int d1=a.st.nd-a.st.st,d2=b.st.nd-b.st.st; if(d1>=0&&d2<0)return 1; if(d2>=0&&d1<0)return 0; if(d1>=0){ return a.st.st<b.st.st; } else{ return a.st.nd>b.st.nd; } } main(){ int n,z; scanf("%d%d",&n,&z); long long s=z; pair<pair<int,int>,int>t[n]; for(int i=0;i<n;i++){ scanf("%d%d",&t[i].st.st,&t[i].st.nd); t[i].nd=i; } sort(t,t+n,comp); //for(int i=0;i<n;i++)cout<<t[i].st.st<<" "<<t[i].st.nd<<"\n"; for(int i=0;i<n;i++){ s-=t[i].st.st; if(s<=0){printf("NIE\n");return 0;} s+=t[i].st.nd; } printf("TAK\n"); for(int i=0;i<n;i++)printf("%d ",t[i].nd+1); printf("\n"); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #include<stdio.h> #include<algorithm> #define st first #define nd second using namespace std; bool comp(pair<pair<int,int>,int> a,pair<pair<int,int>,int> b){ int d1=a.st.nd-a.st.st,d2=b.st.nd-b.st.st; if(d1>=0&&d2<0)return 1; if(d2>=0&&d1<0)return 0; if(d1>=0){ return a.st.st<b.st.st; } else{ return a.st.nd>b.st.nd; } } main(){ int n,z; scanf("%d%d",&n,&z); long long s=z; pair<pair<int,int>,int>t[n]; for(int i=0;i<n;i++){ scanf("%d%d",&t[i].st.st,&t[i].st.nd); t[i].nd=i; } sort(t,t+n,comp); //for(int i=0;i<n;i++)cout<<t[i].st.st<<" "<<t[i].st.nd<<"\n"; for(int i=0;i<n;i++){ s-=t[i].st.st; if(s<=0){printf("NIE\n");return 0;} s+=t[i].st.nd; } printf("TAK\n"); for(int i=0;i<n;i++)printf("%d ",t[i].nd+1); printf("\n"); } |