QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#711417 | #9528. New Energy Vehicle | confirm14478 | WA | 3ms | 15972kb | C++20 | 1.6kb | 2024-11-05 10:41:44 | 2024-11-05 10:41:45 |
Judging History
answer
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define int long long
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define endl "\n"
#define debug cout<<'*'<<'\n'
const int N = 2e5 + 500, M = 5e5 + 500;
const int mod = 1e9 + 7, inf = 2e18+50;
using namespace std;
using pii=pair<int,int>;
int a[N],val[N],dis[N];
priority_queue<int,vector<int>,greater<int>> place[N];
pii op[N];
struct node {
int col,dis;
friend bool operator<(const node &a, const node &b) {
return a.dis>b.dis;
}
};
void solve()
{
int n,m;cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++) {
while(!place[i].empty())place[i].pop();
place[i].push(inf);
val[i]=a[i];
}
for(int i=1;i<=m;i++) {
cin>>op[i].second>>op[i].first;
place[op[i].first].push(op[i].second);
}
priority_queue<node> q;
for(int i=1;i<=n;i++)
q.push({i,place[i].top()});
int ans=0;
for(int i=1;i<=m;i++) {
int tmp=op[i].second-ans;
while(!q.empty()&&tmp>0) {
node u=q.top();q.pop();
if(val[u.col]<tmp) {
tmp-=val[u.col];
val[u.col]=0;
}else {
val[u.col]-=tmp;
tmp=0;
q.push(u);
}
}
if(tmp>0)break;
else ans=op[i].second;
place[op[i].first].pop();
if(q.top().col==op[i].first) q.pop();
val[op[i].first]=a[op[i].first];
q.push({op[i].first,place[op[i].first].top()});
}
for(int i=1;i<=n;i++)ans+=val[i];
cout<<ans<<"\n";
}
signed main()
{
//freopen("C:\\Users\\win11\\Desktop\\test.txt", "r", stdin);
//ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T = 1;
cin >> T;
while (T--)solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 15972kb
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: 3ms
memory: 13840kb
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 11 0 11 0 2000000000
result:
wrong answer 3rd lines differ - expected: '4', found: '0'