Skip to content

Instantly share code, notes, and snippets.

@jgcoded
Last active August 29, 2015 14:23
Show Gist options
  • Save jgcoded/09c8ccebf47db2269d54 to your computer and use it in GitHub Desktop.
Save jgcoded/09c8ccebf47db2269d54 to your computer and use it in GitHub Desktop.
#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