Last active
August 29, 2015 14:23
-
-
Save jgcoded/09c8ccebf47db2269d54 to your computer and use it in GitHub Desktop.
UVA Online Judge submission for Argus (problem # 1203) Link: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=247&page=show_problem&problem=3644
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <queue> | |
#include <vector> | |
#include <string> | |
#include <utility> | |
#include <functional> | |
#include <cstring> | |
using namespace std; | |
typedef pair<int, int> ii; | |
typedef vector<ii> vii; | |
template<class U = greater<int>> | |
struct qiicomp | |
{ | |
bool operator()(ii a, ii b, U u = U()) const | |
{ | |
if(a.second == b.second) | |
return u(a.first, b.first); | |
return u(a.second, b.second); | |
} | |
}; | |
typedef priority_queue<ii, vii, qiicomp<>> qii; | |
int main() | |
{ | |
ios::sync_with_stdio(false); | |
string tmp; | |
int m[3001]; | |
memset(m, 0, sizeof(m)); | |
while(cin >> tmp) | |
{ | |
qii q; | |
int Q, P; | |
// use a map to keep track of how many times something's been added | |
while(tmp != "#") | |
{ | |
cin >> Q >> P; | |
q.push(make_pair(Q, P)); | |
m[Q] = P; | |
cin >> tmp; | |
} | |
int K; | |
cin >> K; | |
while(K--) | |
{ | |
ii p = q.top(); | |
q.pop(); | |
cout << p.first << endl; | |
p.second += m[p.first]; | |
q.push(p); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment