QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#702084 | #7622. Yet Another Coffee | Arkhell | WA | 1ms | 9924kb | C++14 | 2.1kb | 2024-11-02 15:15:59 | 2024-11-02 15:16:00 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+1;
int a[N];
struct Node{
int r;
int x;
}node[N];
bool cmp(Node a,Node b){
return a.r<b.r;
}
int pre[N];
int ans[N];
int flag[N];
int n,m;
void solve(){
cin>>n>>m;
int suma=0;
priority_queue<pair<int,int>>q;
for(int i=1;i<=n;i++){
cin>>a[i];
if(i>=2){
q.push({a[i],i});
}
suma+=a[i];
flag[i]=0;
}
int sum=0;
for(int i=1;i<=m;i++){
cin>>node[i].r>>node[i].x;
sum+=node[i].x;
}
sort(node+1,node+1+m,cmp);
int l=1;
for(int i=1;i<=n;i++){
while(i>node[l].r&&l<=m){
sum-=node[l].x;
l++;
}
pre[i]=sum;
}
int nxt=2;
int fir=1;
ans[n]=suma-pre[1];
for(int i=n-1;i>=2;i--){
int tmp=ans[i+1];
int tmpa=tmp+pre[fir]-a[fir]-pre[nxt];
while(q.size()>0&&flag[q.top().second]){
q.pop();
}
int tmpb=1e18;
if(q.size()>0){
tmpb=tmp-q.top().first;
}
ans[i]=min(tmpa,tmpb);
if(tmpa<tmpb){
flag[fir]=1;
fir=nxt;
flag[fir]=1;
for(int j=nxt+1;j<=n;j++){
if(flag[j]==0){
nxt=j;
break;
}
nxt=n+1;
}
}
else{
flag[q.top().second]=1;
if(flag[nxt]==1){
for(int i=nxt+1;i<=n;i++){
if(flag[i]==0){
nxt=i;
break;
}
nxt=n+1;
}
}
q.pop();
}
}
ans[1]=a[fir]-pre[fir];
for(int i=1;i<=n;i++){
cout<<ans[i]<<' ';
}
cout<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int __;
cin>>__;
while(__--){
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 9924kb
input:
5 10 14 17 37 59 65 53 73 68 177 160 111 10 177 5 193 2 30 3 63 2 339 3 263 5 178 2 190 9 23 10 328 10 200 9 8 3 391 6 230 12 9 152 306 86 88 324 59 18 14 42 260 304 55 3 50 2 170 1 252 7 811 1 713 7 215 10 201 4 926 8 319 19 20 182 74 180 201 326 243 195 31 170 263 284 233 48 166 272 281 179 116 31...
output:
-2596 -2559 -2506 -2447 -2382 -2314 -2241 -2130 -1970 -1793 -3505 -3491 -3473 -3431 -3376 -3317 -3231 -3143 -2883 -2579 -2273 -1949 -6527 -6496 -6448 -6374 -6258 -6092 -5922 -5743 -5563 -5368 -5167 -4934 -4691 -4428 -4156 -3875 -3591 -3272 -2946 -3219 -2987 -2572 -2140 -1707 -1238 -768 -274 243 1...
result:
ok 70 numbers
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 9680kb
input:
2 5 2 1 2 3 4 5 3 1 4 2 7 3 4 3 1 10 3 8 6 4 9 3 8 4 5
output:
-2 0 3 7 12 -19 -18 -15 -11 -5 3 13
result:
wrong answer 6th numbers differ - expected: '-21', found: '-19'