QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#685666#9528. New Energy Vehicleyxd#WA 1ms7796kbC++141.4kb2024-10-28 20:42:072024-10-28 20:42:10

Judging History

This is the latest submission verdict.

  • [2024-10-28 20:42:10]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 7796kb
  • [2024-10-28 20:42:07]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+10;
pair<int,int> a[N];
int b[N],c[N];
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        int n,m;
        cin>>n>>m;

        for(int i=1;i<=n;i++){
            cin>>b[i];
            c[i]=b[i];
        }
        for(int i=1;i<=m;i++){
            cin>>a[i].first>>a[i].second;
        }
        sort(a+1,a+m+1);

        int res=0,pre=1,idx=0;
        for(int i=1;i<=m;i++){
            if(a[i].first>b[a[i].second]){
                res+=b[a[i].second];
                idx+=b[a[i].second];
                b[a[i].second]=0;
            }else{
                res+=a[i].first-idx;
                idx=a[i].first;
            }
            while(idx>=a[pre].first){
                b[a[pre].second]=c[a[pre].second];
                pre++;
                if(pre>m)break;
            }
        }
        for(int i=1;i<=n;i++){
            if(b[i]){
                idx+=b[i];
            }else{
                continue;
            }
            while(idx>=a[pre].first){
                b[a[pre].second]=c[a[pre].second];
                pre++;
                if(pre>m)break;
            }
        }
        for(int i=1;i<=n;i++){
            res+=b[i];
        }
        cout<<res<<"\n";
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7748kb

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: 7796kb

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:

8
11
4
11
999999999
2000000000

result:

wrong answer 1st lines differ - expected: '9', found: '8'