用优先队列模拟一下就ok啦。
1 #include2 #include 3 #include 4 #include 5 using namespace std; 6 7 const int N = 3001; 8 int mp[N]; 9 10 struct Node 11 {12 int id, time;13 Node(){}14 Node( int _id, int _time )15 {16 id = _id, time = _time;17 }18 bool operator < ( const Node & o ) const 19 {20 if ( time != o.time ) return time > o.time;21 return id > o.id;22 }23 };24 25 priority_queue q;26 27 int main ()28 {29 char cmd[11];30 while ( scanf("%s", cmd) != EOF )31 {32 if ( cmd[0] == '#' ) break;33 int _id, _time;34 scanf("%d%d", &_id, &_time);35 q.push( Node( _id, _time ) );36 mp[_id] = _time;37 }38 int m;39 scanf("%d", &m);40 while ( m-- )41 {42 Node cur = q.top();43 q.pop();44 printf("%d\n", cur.id);45 cur.time += mp[cur.id];46 q.push(cur);47 }48 return 0;49 }