Problem:
There are
n
processes in a queue. Each process has name
i
and time
i
.  The round-robin scheduling handles the processes in order. A round-robin scheduler gives each process a
quantum
(a time slot) and interrupts the process if it is not completed by then. The process is resumed and moved to the end of the queue, then the scheduler handles the next process in the queue.
For example, we have the following queue with the quantum of 100ms.
A(150) - B(80) - C(200) - D(200)
First, process A is handled for 100ms, then the process is moved to the end of the queue with the remaining time (50ms).
B(80) - C(200) - D(200) - A(50)
Next, process B is handled for 80ms. The process is completed with the time stamp of 180ms and removed from the queue.
C(200) - D(200) - A(50)
Your task is to write a program which simulates the round-robin scheduling
.
Input
n
q
name
1
time
1
name
2
time
2
...
name
n
time
n
In the first line the number of processes
n
and the quantum
q
are given separated by a single space.
In the following
n
lines, names and times for the
n
processes are given.
name
i
and
time
i
are separated by a single space.
Output
For each process, prints its name and the time the process finished in order.
Constraints
1 ≤
n
≤ 100000
1 ≤
q
≤ 1000
1 ≤
time
i
≤ 50000
1 ≤ length of
name
i
≤ 10
1 ≤ Sum of
time
i
≤ 1000000
Sample Input 1
5 100
p1 150
p2 80
p3 200
p4 350
p5 20
Sample Output 1
p2 180
p5 400
p1 450
p3 550
p4 800
Notes
Template in C

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define int long long
const int mod = 1000000007;
#define srt(v) sort(v.begin(), v.end());
#define srt_Dec(v) sort(v.begin(), v.end(), greater<int>());

int solve1(){

    return 0;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n, time;
    cin >> n >> time;

    int total_time = 0;
    queue<pair<string, int>> q;

    while(n--){
        string s;
        int t;

        cin >> s >> t;
        q.push({s, t});
    }

    // while(q.size()!=0){
    //     cout << q.front().first << " " << q.front().second << "\n";
    //     q.pop();
    // }

    vector<pair<int,  string>> v;
    while(q.size()!=0){
        if(q.front().second>time){
            total_time += time;

            q.front().second -= time;

            q.push(q.front());
            q.pop();
        }

        else if(q.front().second<=time){
            total_time += q.front().second;

            v.push_back({total_time, q.front().first});
            q.pop();
        }
    }




    srt(v);
    for (int i = 0; i < v.size();i++){
        cout << v[i].second << " " << v[i].first << "\n";
    }

        return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 7712
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,qnt;
    cin >> n >> qnt;

    string name[100005];
    int time[100005];

    for(int i=0;i<n;i++)
    {
        cin >> name[i] >> time[i];
    }

    int q[200005];
    int head=0,tail=0;

    for(int i=0;i<n;i++)
    {
        q[tail++]=i;
    }

    int currentTime=0;

    while(head<tail)
    {
        int idx=q[head++];

        if(time[idx]<=qnt)
        {
            currentTime+=time[idx];
            cout << name[idx] << " " << currentTime << endl;
        }
        else
        {
            currentTime+=qnt;
            time[idx]-=qnt;
            q[tail++]=idx;
        }
    }

    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 7304
final_rank: 18

code_snippet: // ██████████████████╗█████╗███╗   ██╗    ██████╗ █████╗████╗   ██╗█████╗███╗   ██╗
// ╚══██╔══██╚══██╔══██╔══██████╗  ██║    ██╔══████╔══████╚██╗ ██╔██╔══██████╗  ██║
//    ██║  ██║  ██║  █████████╔██╗ ██║    ██████╔█████████║╚████╔╝█████████╔██╗ ██║
//    ██║  ██║  ██║  ██╔══████║╚██╗██║    ██╔══████╔══████║ ╚██╔╝ ██╔══████║╚██╗██║
//    ██║  ██║  ██║  ██║  ████║ ╚████║    ██║  ████║  ████║  ██║  ██║  ████║ ╚████║
//    ╚═╝  ╚═╝  ╚═╝  ╚═╝  ╚═╚═╝  ╚═══╝    ╚═╝  ╚═╚═╝  ╚═╚═╝  ╚═╝  ╚═╝  ╚═╚═╝  ╚═══╝
// GitHub: https://github.com/raiyansarker/cp

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;typedef unsigned long long ull;typedef long double ld;typedef pair<int,int> pii;typedef pair<ll,ll> pll;typedef vector<int> vi;typedef vector<ll> vll;typedef vector<pii> vpii;typedef vector<pll> vpll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()

#ifndef NDEBUG
namespace dbg{string s(int x){return to_string(x);}string s(long long x){return to_string(x);}string s(unsigned long long x){return to_string(x);}string s(double x){return to_string(x);}string s(long double x){return to_string(x);}string s(char x){return "'"+string(1,x)+"'";}string s(string x){return '"'+x+'"';}string s(bool x){return x?"true":"false";}string s(const char*x){return'"'+string(x)+'"';}template<class A,class B>string s(pair<A,B>p){return"("+s(p.first)+","+s(p.second)+")";}template<class T>string s(T v){string r="{";for(auto x:v)r+=(r=="{"?"":","),r+=s(x);return r+"}";}template<class T>string s(stack<T>st){string r="{";while(!st.empty())r+=(r=="{"?"":","),r+=s(st.top()),st.pop();return r+"}";}template<class T>string s(queue<T>q){string r="{";while(!q.empty())r+=(r=="{"?"":","),r+=s(q.front()),q.pop();return r+"}";}template<class T>string s(priority_queue<T>pq){string r="{";while(!pq.empty())r+=(r=="{"?"":","),r+=s(pq.top()),pq.pop();return r+"}";}void p(const char*n){cerr<<"\n";}template<class T>void p(const char*n,T v){cerr<<n<<"="<<s(v)<<"\n";}template<class T,class...A>void p(const char*n,T v,A...a){for(;*n!=',';n++)cerr<<*n;cerr<<"="<<s(v)<<", ";p(n+1,a...);}}
#define debug(...) cerr<<"[L"<<__LINE__<<"]: ",dbg::p(#__VA_ARGS__,__VA_ARGS__)
#else
#define debug(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
    
  int n, tl; cin >> n >> tl;

  // queue for processing
  queue<pair<int, string>> q;
  // storing time taken to solve
  map<string, int> m;

  // set to sort again
  set<pair<int, string>> s;

  for (int i = 0; i < n; i++) {
    string s; int x;
    cin >> s >> x;
    q.push(mp(x, s));
    m[s] = 0;
  }

  ll prefix_sum = 0;
  while (!q.empty()) {
    // per batch size
    int s = sz(q);
    
    for (int i = 0; i < s; i++) {
      auto node = q.front();
      if (node.first <= tl) {
        prefix_sum += node.first;
        m[node.second] = prefix_sum;
      } else {
        prefix_sum += tl;
        m[node.second] += prefix_sum;
        q.push(mp(node.first - tl, node.second));
      }

      q.pop();
    }
  }

  for (auto d : m) s.insert(mp(d.second, d.first));

  for (auto d : s) {
    cout << d.second << " " << d.first << endl;
  }
    
  return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 11256
final_rank: 20

code_snippet: //                              ✝
#include <bits/stdc++.h>
#define IOS                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
    cout.tie(NULL);
#define ll int
#define ld long double
#define E '\n'
#define read(v, n)            \
for (int i = 0; i < n; i++) \
cin >> v[i];
#define cout(v, n)            \
for (int i = 0; i < n; i++) \
cout << v[i] << " ";
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()


using namespace std;

    
void file()
{
    #ifndef ONLINE_JUDGE
    freopen("C:\\Users\\hp\\Desktop\\c++\\input.txt","r", stdin);
    freopen("C:\\Users\\hp\\Desktop\\c++\\output.txt","w", stdout);
    #endif 
}



int main() {
    IOS 

    
    ll t = 1 ;
    //cin >> t ; 
    while(t--){
    ll n , m ; cin >> n >> m;
    queue<pair<string,ll>> qu ;
    for(int i = 0 ; i < n ; i++){
        string s ; cin >> s ;
        ll x ; cin >> x ;
        qu.push({s,x});
    }
    ll c = 0 ;
    while(!qu.empty()){
    ll d = qu.front().second - m;
    if(d>0){
        qu.push({qu.front().first,d});
        c += m ;
        qu.pop();
    }
    else{
        c += qu.front().second ;
        cout << qu.front().first << " " << c << E ;
        qu.pop();
        
    }
    }

    
    }
    return 0;
}
/*
10
1 2 3 4 5 4 3 2 1 6
1 2 3 4 5 6 7 8 9 10
6 4 4 3 3 2 2 1 1 1 

10 1 1  10 => 1
7 1 2   7  => 2
5 1 3   5  => 3
3 1 4   3  => 4
1 1 5   1  => 5
1 2 4   2  => 4
1 4 3   4  => 3
1 6 2   6  => 2
2 8 1   8  => 1
1 1 6   1  => 6

6 4 4 3 3 2 2 1 - 1

5 3 2
*/
accuracy: 1
time_ms: 10
memory_kb: 5372
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define nl '\n'
typedef long long ll;

int main()
{
    int n,q;
    cin>>n>>q;
    map<string,int> procesos;
    queue<string> cola;
    for(int i=0;i<n;i++)
    {
        string a;
        int b;
        cin>>a>>b;
        procesos[a]=b;
        cola.push(a);
    }
    vector<string> ordenados;
    int tiempototal=0;
    while(!cola.empty())
    {
        string b=cola.front();
        if(procesos[b]>q)
        {
            procesos[b]=procesos[b]-q;
            cola.push(b);
            cola.pop();
            tiempototal+=q;
        }   
        else
        {
            ordenados.push_back(b);
            cola.pop();
            int z=procesos[b];
            procesos[b]=tiempototal+procesos[b];
            tiempototal+=z;

        }
    }
    for(int i=0;i<n;i++)
    {
        cout<<ordenados[i]<<" "<<procesos[ordenados[i]]<<nl;
    }

}
accuracy: 1
time_ms: 70
memory_kb: 10528
final_rank: 19

code_snippet: #include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main() {
 ios_base::sync_with_stdio(false);
 cin.tie(nullptr);cout.tie(nullptr);

 int n,time;
 cin>>n>>time;

 queue<pair<string,int>>que;
 for(int i=0; i<n; i++){
    string s;
    int t;
    cin>>s>>t;
    que.push({s,t});
 }

 ll total=0;

 while (!que.empty())
 {
    auto curr=que.front();
    que.pop();
    string pname=curr.first;
    int tm=curr.second;
     
    if(tm>time){
       total+=time;
       que.push({curr.first,tm-time});
    }
    else{
        total+=curr.second;
        cout<<pname<<" "<<total<<endl;
    }

 }
 

 return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 5424
final_rank: 15

code_snippet: #include <bits/stdc++.h>

using namespace std;

int n, q;
queue<pair<string, int>> Q;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    cin >> n >> q;
    for(int i = 0; i < n; i++) {
        string name;
        int t;
        cin >> name >> t;
        Q.push({name, t});
    }

    int curTime = 0;
    while(!Q.empty()) {
        auto [name, t] = Q.front();
        Q.pop();

        curTime += min(q, t);
        t -= min(q, t);

        if(!t) cout << name << ' ' << curTime << '\n';
        else Q.push({name, t});
    }

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 5224
final_rank: 3

code_snippet: #include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main() {
    int N, Q;
    cin >> N >> Q;

    vector<string> names(N);
    vector<int> times(N);
    queue<int> Que;

    for (int i = 0; i < N; ++i) {
        cin >> names[i] >> times[i];
        Que.push(i);
    }
    int current_time = 0;
    while (!Que.empty()) {
        int idx = Que.front();
        Que.pop();
        if (times[idx] > Q) {
            current_time += Q;
            times[idx] -= Q;
            Que.push(idx);
        } else {
            current_time += times[idx];
            cout << names[idx] << " " << current_time << endl;
        }
    }

}
accuracy: 1
time_ms: 40
memory_kb: 5100
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;

int head, tail, MAX;

void initialize() { head = tail = 0; }

bool isEmpty() { return head == tail; }

bool isFull() { return head == (tail + 1) % MAX; }


//配列に入れる
void enqueue(vector<pair<string,int>>& Q, string s,int x) {
    if (isFull()) {
        cout << "error" << endl;
        return;
    }
    Q[tail].first = s;
    Q[tail].second = x;
    if(tail + 1 == MAX)
    {
        tail = 0;
    }
    else
    {
        tail++;
    }
}


//先頭の要素を取り出す
pair<string,int> dequeue(vector<pair<string,int>>& Q) {
    if (isEmpty()) {
        cout << "error" << endl;
        return {"", -1};
    }
    string s = Q[head].first;
    int x = Q[head].second;

    if(head + 1 == MAX)
    {
        head = 0;
    }
    else
    {
        head++;
    }
    return  {s, x};
}

int main() {
    int n,q;
    cin >> n >> q;
    MAX = n + 1;
    vector<pair<string,int>> Q(MAX);

    initialize();//初期化
    for (int i = 0; i < n; i++) {
        string s;
        int x;
        cin >> s >> x;
        enqueue(Q, s,x);//配列に入れる
    }
    
    int time = 0;
    while (!isEmpty()) {
        pair<string,int> p = dequeue(Q);
        string s = p.first;
        int x = p.second;

        //cout << " While " << s << ' ' << x << endl;
        if(x<=q)
        {
            //この時点で配列に入れないから自動的に消える
            time += x;
            cout << s << ' ' << time << endl;
        }
        else
        {
            x -= q;
            time += q;
           // cout << "else  " << time << endl;
            enqueue(Q, s,x);
        }
    }
}
accuracy: 1
time_ms: 50
memory_kb: 4892
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;

int head, tail, MAX;

void initialize() { head = tail = 0; }

bool isEmpty() { return head == tail; }

bool isFull() { return head == (tail + 1) % MAX; }


//配列に入れる
void enqueue(vector<pair<string,int>>& Q, string s,int x) {
    if (isFull()) {
        cout << "error" << endl;
        return;
    }
    Q[tail].first = s;
    Q[tail].second = x;
    if(tail + 1 == MAX)
    {
        tail = 0;
    }
    else
    {
        tail++;
    }
}


//先頭の要素を取り出す
pair<string,int> dequeue(vector<pair<string,int>>& Q) {
    if (isEmpty()) {
        cout << "error" << endl;
        return {"", -1};
    }
    string s = Q[head].first;
    int x = Q[head].second;

    if(head + 1 == MAX)
    {
        head = 0;
    }
    else
    {
        head++;
    }
    return  {s, x};
}

int main() {
    int n, q;
    cin >> n >> q;
    MAX = n + 1;
    vector<pair<string,int>> Q(MAX);
    initialize();

    for (int i = 0; i < n; i++) {
        string s; int x;
        cin >> s >> x;
        enqueue(Q, s, x);
    }

    int time = 0;
    while (!isEmpty()) {
        pair<string,int> p = dequeue(Q);
        string s = p.first;
        int x = p.second;

        if (x <= q) {
            time += x;
            cout << s << ' ' << time << '\n';
        } else {
            x -= q;
            time += q;
            enqueue(Q, s, x);
        }
    }
}
accuracy: 1
time_ms: 20
memory_kb: 4876
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;

int head, tail, MAX;

void initialize() { head = tail = 0; }

bool isEmpty() { return head == tail; }
bool isFull() { return head == (tail + 1) % MAX; }

void enqueue(vector<pair<string,int>>& Q, string s, int x) {
    if (isFull()) {
        cout << "error" << endl;
        return;
    }
    Q[tail].first = s;
    Q[tail].second = x;
    tail = (tail + 1) % MAX;
}

pair<string,int> dequeue(vector<pair<string,int>>& Q) {
    if (isEmpty()) {
        cout << "error" << endl;
        return {"", -1};
    }
    string s = Q[head].first;
    int x = Q[head].second;
    head = (head + 1) % MAX;
    return {s, x}; // ← ここが安全
}

int main() {
    int n, q;
    cin >> n >> q;
    MAX = n + 1;
    vector<pair<string,int>> Q(MAX);
    initialize();

    for (int i = 0; i < n; i++) {
        string s; int x;
        cin >> s >> x;
        enqueue(Q, s, x);
    }

    int time = 0;
    while (!isEmpty()) {
        pair<string,int> p = dequeue(Q);
        string s = p.first;
        int x = p.second;

        if (x <= q) {
            time += x;
            cout << s << ' ' << time << '\n';
        } else {
            x -= q;
            time += q;
            enqueue(Q, s, x);
        }
    }
}
accuracy: 1
time_ms: 20
memory_kb: 4932
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;

struct Process {
    string name;
    int time;
};

int main() {
    int n, q;
    cin >> n >> q;
    
    queue<Process> Q;
    
    // プロセスをキューに追加
    for (int i = 0; i < n; i++) {
        string name;
        int time;
        cin >> name >> time;
        Q.push({name, time});
    }
    
    int current_time = 0;
    
    // ラウンドロビンスケジューリング
    while (!Q.empty()) {
        Process p = Q.front();
        Q.pop();
        
        if (p.time <= q) {
            // プロセスが完了
            current_time += p.time;
            cout << p.name << " " << current_time << endl;
        } else {
            // まだ処理が残っている
            current_time += q;
            p.time -= q;
            Q.push(p);
        }
    }
    
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 5420
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;

struct Process {
    string name;
    int time;
};

int head, tail, MAX;
vector<Process> Q;

void initialize(int n) {
    head = tail = 0;
    MAX = n + 1;
    Q.resize(MAX);
}

bool isEmpty() { return head == tail; }
bool isFull() { return head == (tail + 1) % MAX; }

void enqueue(const Process& p) {
    if (isFull()) {
        cout << "error: queue full\n";
        return;
    }
    Q[tail] = p;
    tail = (tail + 1) % MAX;
}

Process dequeue() {
    if (isEmpty()) {
        cout << "error: queue empty\n";
        return {"", -1};
    }
    Process p = Q[head];
    head = (head + 1) % MAX;
    return p;
}

int main() {
    int n, q;
    cin >> n >> q;
    initialize(n);

    for (int i = 0; i < n; i++) {
        string name;
        int t;
        cin >> name >> t;
        enqueue({name, t});
    }

    int elapsed = 0;
    while (!isEmpty()) {
        Process p = dequeue();
        if (p.time > q) {
            elapsed += q;
            p.time -= q;
            enqueue(p);
        } else {
            elapsed += p.time;
            cout << p.name << " " << elapsed << "\n";
        }
    }
}
accuracy: 1
time_ms: 10
memory_kb: 4648
final_rank: 1

code_snippet: #include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <cstdint>

int main() {
    int N;
    int Q;
    std::cin >> N >> Q;

    std::vector<std::string> names(N);
    std::vector<int> times(N);
    std::queue<int> Que;

    for (int i = 0; i < N; ++i) {
        std::cin >> names[i] >> times[i];
        Que.push(i);
    }

    int tmp;
    int idx;
    int t = 0;

    while (!Que.empty()) {
        idx = Que.front();
        Que.pop();
        tmp = times[idx];

        if (tmp <= Q) {
            t += tmp;
            std::cout << names[idx] << " " << t << '\n';
        } else {
            times[idx] = tmp - Q;
            t += Q;
            Que.push(idx);
        }
    }

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 5084
final_rank: 2

code_snippet: #include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main(){
int N, Q;
    cin >> N >> Q;
    vector<string> names(N);
    vector<int> times(N);
    queue<int> Que;
    for (int i=0; i<N; ++i) {
        cin >> names[i] >> times[i];
        Que.push(i);
    }
    int passtime = 0;
    while(!Que.empty()){
        int task = Que.front();
        Que.pop();
        if(times[task] > Q) {
            times[task] -= Q;
            passtime += Q;
            Que.push(task);
        }
        else {
            passtime += times[task];
            cout << names[task] << ' ' << passtime << endl;
        }
    }
}
accuracy: 1
time_ms: 40
memory_kb: 5172
final_rank: 11

code_snippet: #include <iostream> 
#include <queue> 
#include <string> 
#include <vector> 
using namespace std; 

int main(){ 
    int N, Q; 
    cin >> N >> Q; 
    vector<string> names(N); 
    vector<int> times(N); 
    queue<int> Que; 
    for (int i=0; i<N; ++i) { 
        cin >> names[i] >> times[i]; 
        Que.push(i); 
    }
    int time = 0;
    while (!Que.empty()) {
        int i = Que.front();
        Que.pop();
        if (times[i] <= Q) {
            time += times[i];
            cout << names[i] << " " << time << endl;
        } else {
            time += Q;
            times[i] -= Q;
            Que.push(i);
        }
    }
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 5024
final_rank: 8

code_snippet: #include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <queue>
using namespace std;

int main(){
    int n,q;
    cin >> n >> q;
    vector<string> names(n);
    vector<int> times(n);
    queue<int> que;
    int t = 0;
    for(int i=0; i<n; i++){
        cin >> names[i] >> times[i];
        que.push(i);
    }
    while(!que.empty()){
        int i = que.front();
        que.pop();
        if (times[i] > q){
            times[i] -= q;
            t += q;
            que.push(i);
        }else{
            t += times[i];
            cout << names[i] << " " << t << endl;
            times[i] = 0;   // アルゴリズム的には不要
        }
    }
}
accuracy: 1
time_ms: 40
memory_kb: 5068
final_rank: 9

code_snippet: #include <iostream>
#include <queue>
#include <string>
using namespace std;

struct Process {
    string name;  // プロセス名
    int time;     // 残りの処理時間
};

int main() {
    int n, q;
    cin >> n >> q; // n: プロセス数, q: クオンタム（1回の処理時間）

    queue<Process> Q;  // プロセスを管理するキュー

    // プロセス情報を読み込み
    for (int i = 0; i < n; i++) {
        Process p;
        cin >> p.name >> p.time;
        Q.push(p);
    }

    int elapsed = 0;  // 経過時間

    // キューが空になるまで処理を繰り返す
    while (!Q.empty()) {
        Process current = Q.front(); // 先頭のプロセスを取り出す
        Q.pop();

        if (current.time <= q) {
            // 残り時間がクオンタム以下 → 完了
            elapsed += current.time;
            cout << current.name << " " << elapsed << endl;
        } else {
            // まだ残りがある → qだけ処理して末尾に戻す
            elapsed += q;
            current.time -= q;
            Q.push(current);
        }
    }

    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 5516
final_rank: 16

code_snippet: #include <iostream>
#include <queue>
#include <string>
using namespace std;

struct Process {
    string name;\
    int time;
};

int main() {
    int n, q;
    cin >> n >> q;

    queue<Process> Q;

    for (int i = 0; i < n; i++) {
        Process p;
        cin >> p.name >> p.time;
        Q.push(p);
    }

    int elapsed = 0;

    while (!Q.empty()) {
        Process current = Q.front();
        Q.pop();

        if (current.time <= q) {
            elapsed += current.time;
            cout << current.name << " " << elapsed << endl;
        } else {
            elapsed += q;
            current.time -= q;
            Q.push(current);
        }
    }

    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 5408
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main(){
    int n, q;
    int total_time = 0;
    queue<string> name;
    queue<int> time;

    cin >> n >> q;

    
    for(int i=0; i<n; ++i){
        string str;
        int j;
        cin >> str >> j;
        name.push(str);
        time.push(j);
    }
    
    while(!time.empty()){
        int headtime = time.front();
        string headname = name.front();
        if(headtime-q>0){
            name.pop();
            time.pop();
            name.push(headname);
            time.push(headtime-q);
            total_time += q;
        }
        else{
            name.pop();
            time.pop();
            
            total_time += headtime;

            cout << headname << " " << total_time << endl;
        }

    }
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 5308
final_rank: 12