Submission #73483854


Source Code Expand

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

using ll=long long;
using ull=unsigned long long;

void solve(){
    ll N, D; cin>>N>>D;
    vector<ll> A(N), B(N);
    for(int i=0; i<N; ++i)cin>>A[i];
    for(int i=0; i<N; ++i)cin>>B[i];

    queue<pair<ll, ll>> Q;
    for(int i=0; i<N; ++i){
        Q.push({i, A[i]});

        int b=B[i];
        while(b>0){
            auto [d, n]=Q.front();
            if(b>=n){
                Q.pop();
                b-=n;
            }else{
                Q.front().second-=b;
                b=0;
            }
        }

        while(!Q.empty()&&i-Q.front().first>=D)Q.pop();
    }

    ll ans=0;
    while(!Q.empty()){
        ans+=Q.front().second;
        Q.pop();
    }
    cout<<ans<<endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //cout<<fixed<<setprecision(17);
    int T=1; cin>>T;
    while(T--)solve();
    return 0;
}

Submission Info

Submission Time
Task C - Omelette Restaurant
User Aseteyan
Language C++23 (GCC 15.2.0)
Score 300
Code Size 973 Byte
Status AC
Exec Time 32 ms
Memory 9304 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 1
AC × 30
Set Name Test Cases
Sample example_00.txt
All example_00.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3424 KiB
hand_00.txt AC 13 ms 9304 KiB
hand_01.txt AC 15 ms 6420 KiB
hand_02.txt AC 12 ms 6496 KiB
hand_03.txt AC 12 ms 6420 KiB
hand_04.txt AC 12 ms 6496 KiB
hand_05.txt AC 32 ms 3632 KiB
hand_06.txt AC 12 ms 7772 KiB
hand_07.txt AC 23 ms 5600 KiB
hand_08.txt AC 2 ms 3652 KiB
random_00.txt AC 16 ms 3664 KiB
random_01.txt AC 16 ms 3640 KiB
random_02.txt AC 17 ms 3632 KiB
random_03.txt AC 16 ms 3448 KiB
random_04.txt AC 17 ms 3632 KiB
random_05.txt AC 11 ms 3792 KiB
random_06.txt AC 11 ms 3700 KiB
random_07.txt AC 11 ms 3904 KiB
random_08.txt AC 11 ms 3704 KiB
random_09.txt AC 11 ms 3920 KiB
random_10.txt AC 13 ms 6496 KiB
random_11.txt AC 13 ms 6492 KiB
random_12.txt AC 13 ms 6568 KiB
random_13.txt AC 13 ms 6492 KiB
random_14.txt AC 13 ms 6492 KiB
random_15.txt AC 13 ms 6392 KiB
random_16.txt AC 13 ms 6536 KiB
random_17.txt AC 13 ms 6556 KiB
random_18.txt AC 13 ms 6496 KiB
random_19.txt AC 13 ms 6480 KiB