QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#689298 | #9528. New Energy Vehicle | Swd146296# | WA | 1ms | 5684kb | C++14 | 1.5kb | 2024-10-30 16:15:16 | 2024-10-30 16:15:16 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#define int long long
using namespace std;
typedef pair<int,int> PII;
const int MX=100020;
const int inf=1e18;
int N, M, T;
int ar[MX], now[MX];
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;
}
struct node
{
int x, t, c;
bool operator < (const node &a)const {return x<a.x;}
}pos[MX];
priority_queue<PII> q;
signed main()
{
// freopen("testdata.in","r",stdin);
T=read();
while(T--)
{
N=read(); M=read();
int ans=0;
for(int i=1;i<=N;i++) ar[i]=read(), ans+=ar[i];
for(int i=1;i<=N;i++) now[i]=0;
while(!q.empty()) q.pop();
for(int i=1;i<=M;i++)
{
pos[i].x=read();
pos[i].t=read();
pos[i].c=min(ar[pos[i].t],pos[i].x-now[pos[i].t]);
int l=pos[i].x-pos[i].c, r=pos[i].x;
while(!q.empty())
{
auto [lq,rq]=q.top();
if(rq<=l) break;
else if(lq<=l&&rq>l) {pos[i].c-=rq-l; q.pop();}
else if(lq>l) {pos[i].c-=(rq-lq); q.pop();}
}
q.push({l,r});
now[pos[i].t]=pos[i].x;
}
sort(pos+1,pos+1+M);
for(int i=1;i<=M;i++)
{
if(ans>pos[i].x) ans+=pos[i].c;
}
cout << ans << '\n';
}
return (0-0);
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5684kb
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: 5620kb
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:
6 11 4 11 999999999 1000000000
result:
wrong answer 1st lines differ - expected: '9', found: '6'