More actions
No edit summary |
No edit summary |
||
| Line 8: | Line 8: | ||
= 코드 = | = 코드 = | ||
== 15이원준 == | == 15이원준 == | ||
#include<iostream> | |||
#include<algorithm> | |||
#include<set> | |||
#include<utility> | |||
#include<queue> | |||
using namespace std; | |||
class PairCompare | |||
{ | |||
public: | |||
bool operator()(pair<int,int> &p1, pair<int,int> &p2){ | |||
if(p1.first == p2.first){ | |||
return p1.second < p2.second; | |||
} | |||
else{ | |||
return p1.first < p2.first; | |||
} | |||
} | |||
}; | |||
int main(){ | |||
priority_queue<pair<int, int>, vector<pair<int, int>>, PairCompare> que; | |||
multiset<int> bag; | |||
int N, K; | |||
long long int ans = 0; | |||
cin >> N >> K; | |||
for(int i = 0; i<N; i++){ | |||
int tmp1, tmp2; | |||
scanf("%d %d", &tmp1, &tmp2); | |||
que.push(make_pair(tmp2, tmp1)); | |||
} | |||
for(int i = 0; i<K; i++){ | |||
int tmp; | |||
scanf("%d", &tmp); | |||
bag.insert(tmp); | |||
} | |||
while(que.size() && bag.size()){ | |||
pair<int,int> tmp = que.top(); | |||
que.pop(); | |||
auto p = bag.lower_bound(tmp.second); | |||
if(p != bag.end()){ | |||
ans+= tmp.first; | |||
bag.erase(p); | |||
} | |||
} | |||
cout<< ans<<endl; | |||
} | |||
== 박인서 == | == 박인서 == | ||
Revision as of 01:57, 26 September 2016
오늘의 문제
참가자
코드
15이원준
#include<iostream>
#include<algorithm>
#include<set>
#include<utility>
#include<queue>
using namespace std;
class PairCompare
{
public:
bool operator()(pair<int,int> &p1, pair<int,int> &p2){
if(p1.first == p2.first){
return p1.second < p2.second;
}
else{
return p1.first < p2.first;
}
}
};
int main(){
priority_queue<pair<int, int>, vector<pair<int, int>>, PairCompare> que;
multiset<int> bag;
int N, K;
long long int ans = 0;
cin >> N >> K;
for(int i = 0; i<N; i++){
int tmp1, tmp2;
scanf("%d %d", &tmp1, &tmp2);
que.push(make_pair(tmp2, tmp1));
}
for(int i = 0; i<K; i++){
int tmp;
scanf("%d", &tmp);
bag.insert(tmp);
}
while(que.size() && bag.size()){
pair<int,int> tmp = que.top();
que.pop();
auto p = bag.lower_bound(tmp.second);
if(p != bag.end()){
ans+= tmp.first;
bag.erase(p);
}
}
cout<< ans<<endl;
}