QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#705023 | #9528. New Energy Vehicle | DJGoutou | WA | 1ms | 4116kb | C++20 | 1.3kb | 2024-11-02 21:54:47 | 2024-11-02 21:54:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
typedef long long ll;
int w[N],num[N];
struct cc
{
int x,id;
}a[N];
bool cmp(cc x,cc y)
{
return x.x<y.x;
}
int main()
{
int T,n,m;
cin>>T;
while(T--)
{
a[0].x=0;
memset(num,0,sizeof(num));
ll fr=0,r=0;
cin>>n>>m;
for(int i=1;i<=n;i++)
{cin>>w[i];fr+=w[i];}
for(int i=1;i<=m;i++)
{
cin>>a[i].x>>a[i].id;
if(num[a[i].id]==0)r+=a[i].x;
num[a[i].id]++;
}
fr-=r;
int ids=1;
ll _r=r,st=0;
sort(a+1,a+m+1,cmp);
//int nn=0;
while(r+fr>=a[ids].x-a[ids-1].x&&ids<=m)
{
//nn++;
//cout<<r+fr<<endl;
ll t=a[ids].x-a[ids-1].x;
//cout<<t<<endl;
if(r>=t)
{
r-=t;
r=min(r+w[a[ids].id],_r);
}
else {
r=w[a[ids].id];
fr-=(t-r);
}
num[a[ids].id]--;
if(num[a[ids].id]==0) {_r-=w[a[ids].id];r-=w[a[ids].id];fr+=w[a[ids].id];}
st=a[ids++].x;
}
cout<<st+fr+r<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4108kb
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: 0ms
memory: 4116kb
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:
10 11 4 11 999999999 2000000000
result:
wrong answer 1st lines differ - expected: '9', found: '10'