QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#696630#9528. New Energy VehicletravelWA 1ms5896kbC++142.5kb2024-10-31 23:56:412024-10-31 23:56:41

Judging History

This is the latest submission verdict.

  • [2024-10-31 23:56:41]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 5896kb
  • [2024-10-31 23:56:41]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> PII;
#define endl "\n"
#define ft first
#define sd second
#define pb push_back
const int MOD = 1e9 + 7;
int n,m;
const int N = 1e5 + 10;
int a[N],c[N];
struct node{
    int dis,id;
}b[N];
void solve() {
    cin>>n>>m;
    int sum = 0;
    for(int i = 1;i <= n;i++) {
        cin>>a[i];
        sum +=a[i];
        c[i] = a[i];
    }
//    cout<<sum<<endl;
    queue<node> q;
    map<int,int> mp;
    for(int i = 1;i <= m;i++){
        int x,y; cin>>x>>y;
        b[i] = {x,y};
        mp[x] = 1;
        q.push({x,y});
    }
    queue<int> q1;
    for(int i = 1;i <= n;i++){
        if(!mp.count(i)) q1.push(i);
    }
    b[0] = {0,0};
    int now = 0;
    for(int i = 1;i <= m;i++){
        int d = b[i].dis - b[i - 1].dis;
        if(sum >= d){
            sum -=d;
            // charge out
            while(d && q.size()){
                auto t = q.front(); q.pop();
                int dx = a[t.id];
                if(dx <= d) {
                    d-=dx;
                    a[t.id] = 0;
                }
                else {
                    dx -=d;
                    d = 0;
                    a[t.id] = dx;
//                    cout<<t.id<<' '<<dx<<' '<<endl;
//                    system("pause");
                }
            }
            while(d && q1.size()){
                int t = q1.front(); q1.pop();
                if(d >= a[t]){
                    d -=a[t];
                    a[t] = 0;
                }
                else {
                    a[t]-=d;
                    d = 0;
                }
            }
//            cout<<"begin = "<<endl;
//            for(int i = 1;i <= n;i++)
//                cout<<a[i]<<' ';
//            cout<<endl;
            int dx = c[b[i].id] - a[b[i].id];
            a[b[i].id] = c[b[i].id];
            sum +=dx;
            now +=b[i].dis - b[i - 1].dis;
//            cout<<sum<<' '<<now<<endl;
//            cout<<"end = "<<endl;
//            for(int i = 1;i <= n;i++)
//                cout<<a[i]<<' ';
//            cout<<endl;
        }
        else break;
    }
//    cout<<now<<' '<<sum<<' '<<endl;
    now +=sum;
    cout<<now<<endl;
    return ;
}
signed main() {
//    ios::sync_with_stdio(0);
//    cin.tie(0);
//    cout.tie(0);
    int T = 1;
    cin>>T;
    while(T--)
        solve();
    return 0;
}
/*
2
3 1
3 3 3
8 1
2 2
5 2
1 2
2 1

 */


詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 5896kb

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

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'