qscqesze
Published on 2017-09-02 11:31 in 暂未分类 with qscqesze

# 3709: [PA2014]Bohater

## 链接

http://www.lydsy.com/JudgeOnline/problem.php?id=3709

3 5

3 1

4 8

8 3

TAK

2 3 1

## 代码

#include<bits/stdc++.h>
using namespace std;

vector<pair<pair<int,int>,int> >p1,p2;
vector<int> ans;
bool cmp1(pair<pair<int,int>,int> A,pair<pair<int,int>,int> B){
return A.first.first<B.first.first;
}
bool cmp2(pair<pair<int,int>,int> A,pair<pair<int,int>,int> B){
return A.first.second<B.first.second;
}

int main(){
int n;
long long z;
scanf("%d%lld",&n,&z);
for(int i=1;i<=n;i++){
pair<pair<int,int>,int> x;
scanf("%d%d",&x.first.first,&x.first.second);
x.second = i;
if(x.first.first>=x.first.second){
p1.push_back(x);
}else{
p2.push_back(x);
}
}
sort(p1.begin(),p1.end(),cmp1);
for(int i=0;i<p1.size();i++){
if(z<=p1[i].first.first){
cout<<"NIE"<<endl;
return 0;
}else{
z-=p1[i].first.first;
z+=p1[i].first.second;
ans.push_back(p1[i].second);
}
}
sort(p2.begin(),p2.end(),cmp2);
for(int i=p2.size()-1;i>=0;i--){
if(z<=p2[i].first.first){
cout<<"NIE"<<endl;
return 0;
}else{
z-=p2[i].first.first;
z+=p2[i].first.second;
ans.push_back(p2[i].second);
}
}
cout<<"TAK"<<endl;
for(int i=0;i<ans.size();i++){
cout<<ans[i]<<" ";
}
cout<<endl;
}
posted @ 2017-09-07 16:24  qscqesze  阅读(299)  评论(0编辑  收藏