QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#690483#9528. New Energy Vehiclefrankly6TL 0ms0kbC++171.9kb2024-10-30 22:27:502024-10-30 22:27:51

Judging History

This is the latest submission verdict.

  • [2024-10-30 22:27:51]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 0kb
  • [2024-10-30 22:27:50]
  • Submitted

answer

#include<iostream>
#include<cstdio>
#include<queue>
#define int long long
using namespace std;
typedef pair<int,int> PII;
const int MX=200020;
const int inf=1e18;

int N, M, T;
int ar[MX], br[MX], nxt[MX], x[MX], t[MX], pos[MX];
priority_queue<PII,vector<PII>,greater<PII>> q;
int read()
{
    int r=0, f=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {r=r*10+ch-'0'; ch=getchar();}
    return r*f;
}
signed main()
{
    freopen("testdata.in","r",stdin);
    T=read();
    while(T--)
    {
        N=read(); M=read();
        for(int i=1;i<=N;i++) br[i]=ar[i]=read();
        for(int i=1;i<=M;i++)
        {
            x[i]=read(), t[i]=read();
        }
        for(int i=1;i<=N;i++) pos[i]=M+1;
        for(int i=M;i>=1;i--)
        {
            nxt[i]=pos[t[i]]; //nxt same station
            pos[t[i]]=i;
        }
        for(int i=1;i<=N;i++) //first station of battery i
        {
            q.push({pos[i],i}); //battery queue
            // cout << "pos[i]=" << pos[i] << ", i=" << i << '\n';
        }
        int ans=0, k=1;
        while(!q.empty())
        {
            auto [p,id]=q.top(); q.pop();
            int dis=x[k]-ans; //go to the station k for id
            // cout << "p=" << p << ", id=" << id << ", dis=" << dis << '\n';
            if(ar[id]>=dis)
            {
                // cout << "k=" << k << ", t[k]=" << t[k] << ", id=" << id << '\n';
                ar[id]-=dis;
                ans+=dis;
                ar[t[k]]=br[t[k]];
                if(nxt[k]<=M) q.emplace(nxt[k],t[k]);
                k++;
            }
            else
            {
                ans+=ar[id];
                ar[id]=0;
            }
        }
        for(int i=1;i<=N;i++) 
            ans+=ar[i];
        cout << ans << '\n';
    }
    return (0-0);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

2
3 1
3 3 3
8 1
2 2
5 2
1 2
2 1

output:


result: