#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define eps 1e-6
typedef long long LL;
const double pi = acos(-1.0);
const long long mod = 1e9;
using namespace std;
int N,q,T;
string name;
queue<pair<string,int> > Q;
int main()
{
//ios_base::sync_with_stdio(false); cin.tie(0);
//freopen("int.txt","r",stdin);
//freopen("out.txt","w",stdout);
cin >> N >> q;
for(int i = 0; i < N; i++)
{
cin >> name >> T;
Q.push(make_pair(name, T));
}
pair<string, int> u;
int e = 0, a;
while(!Q.empty())
{
u = Q.front();
Q.pop();
a = min(u.second, q);
u.second -= q;
e += a;
if(u.second > 0)
Q.push(u);
else
cout << u.first << ' ' << e << endl;
}
return 0;
}
B - Queue Aizu - ALDS1_3_B
最新推荐文章于 2018-05-13 14:17:55 发布