努力学习ACM @ 2019-03-13 13:19:47
#include<cstdio>
#include<algorithm>
#include<map>
#include<iostream>
#include<vector>
using namespace std;
typedef pair<int, int> PAIR;
bool cmp(PAIR a, PAIR b) {
return a.second < b.second;
}
int main()
{
int n , s , a , b , number = 0 ;
map<int,int> comp;
map<int, int>::iterator iter;
vector<PAIR> vcomp;
vector<PAIR>::iterator viter;
cin >> n >> s >> a >> b ;
int height = a + b ;
int xi , yi ;
while(n > 0){
cin >> xi >> yi ;
comp.insert(make_pair(xi,yi));
n -- ;
}
for(iter=comp.begin(); iter!=comp.end(); iter++) {
vcomp.push_back(PAIR(iter->first, iter->second));
}
sort(vcomp.begin(), vcomp.end(), cmp);
for(viter=vcomp.begin(); viter!=vcomp.end(); viter++) {
if ( viter -> second <= s && viter -> first <= height ){
s -= viter -> second ;
number ++ ;
}
}
cout << number << endl;
return 0;
}
by 努力学习ACM @ 2019-03-13 13:20:31
测试点3有1000个数据存到map和vector中数据少了一部分是为啥呢?
by Dawn_Sdy @ 2019-03-13 13:33:42
为什么一定要用map和vector呢......
by 天才byt @ 2019-03-13 13:56:33
@dxbdly 大概是
by 努力学习ACM @ 2019-03-13 22:49:15
已经好了 把map改成multimap就过了