贪心。先杀能回血的怪。。
杀能回血的怪的时候,显然是按着血量要求从低往高杀;
杀损血的怪的时候,就按回血量从大到小啥。
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<algorithm> 5 #define ll long long 6 using namespace std; 7 const int maxn=100233; 8 struct zs{int add,need,id;}a[maxn],b[maxn]; 9 int anum,bnum,ans; 10 int A[maxn]; 11 int i,j,k,n; 12 ll m; 13 14 int ra;char rx; 15 inline int read(){ 16 rx=getchar(),ra=0; 17 while(rx<'0'||rx>'9')rx=getchar(); 18 while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,rx=getchar();return ra; 19 } 20 bool cmpa(zs a,zs b){return a.need<b.need;} 21 bool cmpb(zs a,zs b){return a.add>b.add;} 22 int main(){ 23 n=read(),m=read(); 24 for(i=1;i<=n;i++){ 25 j=read(),k=read(); 26 if(j<=k)a[++anum]=(zs){k-j,j,i}; 27 else b[++bnum]=(zs){k,j,i}; 28 } 29 sort(a+1,a+1+anum,cmpa); 30 sort(b+1,b+1+bnum,cmpb); 31 for(i=1;i<=anum;i++) 32 if(m>a[i].need)m+=a[i].add,A[++ans]=a[i].id;else break; 33 if(i<=anum){puts("NIE");return 0;} 34 for(i=1;i<=bnum;i++) 35 if(m>b[i].need)m+=b[i].add-b[i].need,A[++ans]=b[i].id;else break; 36 if(i<=bnum){puts("NIE");return 0;} 37 puts("TAK"); 38 for(i=1;i<n;i++)printf("%d ",A[i]);printf("%d ",A[n]); 39 return 0; 40 }