QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#697814 | #9528. New Energy Vehicle | czrq# | WA | 1ms | 5716kb | C++17 | 1.5kb | 2024-11-01 15:53:10 | 2024-11-01 15:53:13 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=1e5+5;
ll id[M],a[M],n,m,k;
ll b[M];
ll nex[M];
bool vis[M]= {0};
struct node {
ll x,t;
bool operator<(const node n) const {
return x<n.x;
}
} no[M];
bool cmp(node x,node y) {
return x.x<=y.x;
}
void solve() {
cin>>n>>m;
priority_queue<node> q;
for(int i=1; i<=n; i++) {
cin>>a[i];
b[i]=a[i];
vis[i]=0;
nex[i]=0;
id[i]=0;
}
for(int i=1; i<=m; i++) {
cin>>no[i].x>>no[i].t;
vis[no[i].t]=1;
q.push(no[i]);
}
long long an=0;
for(int i=1; i<=n; i++) {
if(vis[i]==0) {
an+=a[i];
}
}
sort(no+1,no+1+m,cmp);
for(int i=m; i>=1; i--) {
if(id[no[i].t]) nex[i]=id[no[i].t];
id[no[i].t]=i;
}
int flag=0;
long long sum=0;
no[0].x=0;
no[0].t=0;
nex[0]=0;
for(int i=0; i<m; i++) {
if(i>=1) {
if(nex[i]) {
q.push(no[nex[i]]);
b[no[i].t]=a[no[i].t];
} else {
an+=a[no[i].t];
}
}
while(q.size()&&no[i].x>=q.top().x)q.pop();
long long res=no[i+1].x-no[i].x;
while(res) {
if(!q.size()) {
an-=res;
res=0;
if(an<0) {
flag=1;
}
break;
}
ll v=q.top().t;
ll ans=min(res,b[v]);
if(ans==b[v]) {
q.pop();
}
res-=ans;
b[v]-=ans;
}
if(flag) {
sum=no[i+1].x+an;
// cout<<i<<"#"<<an<<endl;
break;
}
}
if(flag==0) {
sum=(no[m].x+an+a[no[m].t]);
}
cout<<sum<<endl;
}
int main() {
int t=1;
cin>>t;
while(t--) {
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5716kb
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: 5572kb
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 12 4 12 999999999 2000000000
result:
wrong answer 2nd lines differ - expected: '11', found: '12'