QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#682930 | #9528. New Energy Vehicle | rrt517 | WA | 0ms | 3468kb | C++23 | 1.4kb | 2024-10-27 17:57:38 | 2024-10-27 17:57:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
struct Compare
{
bool operator()(pair<long long,int> a,pair<long long,int> b)
{
return a.first<b.first;
}
};
void solve()
{
int n,m;
cin>>n>>m;
vector<long long> a(n+1),e(n+1),x(m+1),t(m+1);
vector<vector<long long>>pos(n+1);
priority_queue<pair<long long,int>,vector<pair<long long,int>>,Compare>que;
for(int i=1;i<=n;i++)
{
cin>>e[i];
a[i]=e[i];
que.push(make_pair(1e18,i));
}
for(int i=1;i<=m;i++)
{
cin>>x[i]>>t[i];
que.push(make_pair(x[i],t[i]));
pos[t[i]].push_back(x[i]);
}
for(int i=1;i<=n;i++)
pos[i].push_back(1e18);
long long cur=0;
for(int i=1;i<=m;i++)
{
while(!que.empty() and cur<x[i])
{
auto [p,id]=que.top();
if(p<=cur)
{
que.pop();
continue;
}
long long delta=min(x[i]-cur,a[id]);
cur+=delta;
a[id]-=delta;
if(a[id]==0)que.pop();
}
if(cur<x[i])break;
a[t[i]]=e[t[i]];
long long p=*upper_bound(pos[t[i]].begin(),pos[t[i]].end(),cur);
que.push(make_pair(p,t[i]));
}
for(int i=1;i<=n;i++)
cur+=a[i];
cout<<cur<<endl;
}
int main()
{
ios::sync_with_stdio(false);
int T;
cin>>T;
for(int i=1;i<=T;i++)solve();
return 0;
}
// struct Compare
// {
// bool operator()(pair<long long,int> a,pair<long long,int> b)
// {
// return a.first>b.first;
// }
// };
// priority_queue<pair<long long,int>,Compare>que;
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3468kb
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: 3464kb
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 9 4 9 999999999 2000000000
result:
wrong answer 2nd lines differ - expected: '11', found: '9'