Submission #1293723

#TimeUsernameProblemLanguageResultExecution timeMemory
1293723activedeltorreAnts and Sugar (JOI22_sugar)C++20
0 / 100
1 ms428 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#pragma gcc optimize("O3,unroll-loops")
using namespace std;
int main()
{
    int i,j,k,l,n,m,q,t,nr,poz;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>q>>l;
    vector<pair<int,int>>v1;
    vector<pair<int,int>>v2;
    for(long long z=1; z<=q; z++)
    {
        cin>>t>>nr>>poz;
        if(t==1)
        {
            v1.push_back({nr,poz});
            for(int i=v1.size()-2; i>=0; i--)
            {
                if(v1[i].first>v1[i+1].first)
                {
                    swap(v1[i],v1[i+1]);
                }
                else
                {
                    break;
                }
            }
        }
        else
        {
            v2.push_back({nr,poz});
            for(int i=v2.size()-2; i>=0; i--)
            {
                if(v2[i].first>v2[i+1].first)
                {
                    swap(v2[i],v2[i+1]);
                }
                else
                {
                    break;
                }
            }
        }
        long long total=0,st=0,cons=0;
        for(int i=0; i<v1.size(); i++)
        {
            while(v2[st].first<v1[i].first-l && st<v2.size())
            {
                st++;
                cons=0;
            }
            while(v2[st].first<=v1[i].first+l && st<v2.size())
            {
                long long util=v2[st].second-cons;
                if(util>=v1[i].second)
                {
                    cons+=util;
                    total+=util;
                    break;
                }
                else
                {
                    total+=util;
                    st++;
                    cons=0;
                }
            }
        }
        cout<<total<<'\n';
    }
    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...