Submission

Status:

PP-PPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: un8qe_x3

Problemset: ซอมบี้

Language: cpp

Time: 0.298 second

Submitted On: 2025-11-01 14:23:50

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;cin >> n >> k;
    queue<int> tp,cp;int b=k;
    for (int i=0;i<n;i++) {int inc;cin >> inc;tp.push(inc);}
    for (int i=0;i<n;i++) {int inc;cin >> inc;cp.push(inc);}
    while (!tp.empty() || !cp.empty()) {
        if (tp.front()>k && !tp.empty()) {
            cout << "GG" << endl;
            break;
        }
        if (cp.front()>k && !cp.empty()) {
            cout << "GG" << endl;
            break;
        }
        if (tp.front()<=b && !tp.empty()) {
            b -= tp.front();
            tp.pop();
        }
        if (cp.front()<=b && !cp.empty()) {
            b -= cp.front();
            cp.pop();
        }
        while (b > 0) {
            bool processed = false;
            if (!tp.empty() && tp.front() <= b) {
                b -= tp.front();
                tp.pop();
                processed = true;
            }
            if (!cp.empty() && cp.front() <= b) {
                b -= cp.front();
                cp.pop();
                processed = true;
            }
            if (!processed) break;
        }
        b=k;
    }
    if (tp.empty() && cp.empty()) {
        cout << "YAY" << endl;
    }
    return 0;
}