제출 #1329436

#제출 시각아이디문제언어결과실행 시간메모리
1329436liptonekBikeparking (EGOI24_bikeparking)C++20
25 / 100
30 ms7444 KiB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin>>n;

    vector<long long> x(n);

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

    vector<long long> y(n);

    long long total=0;

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

        total+=y[i];
    }

    vector<long long> used(n,0);

    long long assigned=0;

    for(int i=0; i<n; i++)
    {
        long long take=min(x[i],total-assigned);

        used[i]=take;
        assigned+=take;

        if(assigned==total)
        {
            break;
        }
    }

    long long rating=0;

    int upvote=0;
    int downvote=0;

    for(int t=0; t<n; t++)
    {
        long long rem=used[t];

        if(rem<=0)
        {
            continue;
        }

        upvote=max(upvote,t+1);

        while(rem>0 && upvote<n)
        {
            if(y[upvote]==0)
            {
                upvote++;

                continue;
            }

            long long matched=min(rem,y[upvote]);

            y[upvote]-=matched;
            rem-=matched;
            rating+=matched;

            if(y[upvote]==0)
            {
                upvote++;
            }
        }

        if(rem>0)
        {
            long long matched=min(rem,y[t]);

            y[t]-=matched;
            rem-=matched;
        }

        while(rem>0 && downvote<t)
        {
            long long matched=min(rem,y[downvote]);

            y[downvote]-=matched;
            rem-=matched;
            rating-=matched;

            if(y[downvote]==0)
            {
                downvote++;
            }
        }
    }

    cout<<rating<<endl;

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...