題目連接:http://codeforces.com/gym/101873/problem/Kc++
題意:spa
如今給出 $n(1 \le n \le 1e4)$ 個員工,最多能夠裁人 $k$ 人,名字爲 $s_i$ 的員工的薪資爲 $c_i(1 \le c_i \le 1e5)$。code
已知必須節省下 $d(1 \le d \le 1e9)$ 元才能拯救公司,問要裁人哪些人。blog
題解:ci
薪資越高的人越要裁掉。get
(這麼個大水題,竟然沒人發現,交的人很少。多是這套題英語閱讀量有點煩人吧……)string
AC代碼:it
#include<bits/stdc++.h> using namespace std; const int maxn=1e4+10; int n,d,k; struct P{ string s; int c; bool operator<(const P& oth)const { return c>oth.c; } }p[maxn]; int main() { cin>>n>>d>>k; for(int i=1;i<=n;i++) cin>>p[i].s>>p[i].c; sort(p+1,p+n+1); int sum=0; vector<int> ans; for(int i=1;i<=k;i++) { sum+=p[i].c; ans.push_back(i); if(sum>=d) break; } if(sum<d) cout<<"impossible"<<endl; else { cout<<ans.size()<<endl; for(int i=0;i<ans.size();i++) { cout<<p[ans[i]].s<<", YOU ARE FIRED!"<<endl; } } }