QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#690486 | #9528. New Energy Vehicle | frankly6 | WA | 1ms | 11756kb | C++17 | 1.8kb | 2024-10-30 22:28:12 | 2024-10-30 22:28:20 |
Judging History
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()
{
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: 100
Accepted
time: 0ms
memory: 11756kb
input:
2 3 1 3 3 3 8 1 2 2 5 2 1 2 2 1
output:
12 9
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 9760kb
input:
6 3 2 2 2 2 6 1 7 1 2 2 3 3 2 1 6 2 2 3 2 2 5 1 7 2 9 1 2 2 3 3 2 1 6 2 1 1 999999999 1000000000 1 1 1 1000000000 1000000000 1
output:
9 8 4 8 999999999 2000000000
result:
wrong answer 2nd lines differ - expected: '11', found: '8'