QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#689969#9528. New Energy Vehicleucup-team3548WA 1ms7916kbC++202.0kb2024-10-30 19:28:402024-10-30 19:28:42

Judging History

This is the latest submission verdict.

  • [2024-10-30 19:28:42]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 7916kb
  • [2024-10-30 19:28:40]
  • Submitted

answer

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll=long long;
const int maxn=1e6+5;
const ll mod=1e9+7;
ll b[maxn],bmx[maxn];
pair<ll,ll> pos[maxn];
void solve() {
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++) {
        cin>>b[i];
        bmx[i]=b[i];
    }
    queue<ll> q[n+1];
    for(int i=1;i<=m;i++) {
        cin>>pos[i].first>>pos[i].second;
        q[pos[i].second].push(pos[i].first);
    }
    ll sum=0;
    priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<>> pq;
    for(int i=1;i<=n;i++) {
        sum+=b[i];
        if(!q[i].empty()) {
            pq.push({q[i].front(),i});
            q[i].pop();
        }
    }
    ll last=0;
    pos[m+1]={1e18,0};
    for(int now=1;now<=m+1;now++) {
        ll d=pos[now].first-last;
        if(d>sum) {
            cout<<last+sum<<"\n";
            return;
        }
        while (!pq.empty()&&pq.top().first<now) {
            pair<ll,ll> p=pq.top();
            pq.pop();
            if(!q[p.second].empty()) {
                pq.push({q[p.second].front(),p.second});
                q[p.second].pop();
            }
        }
        sum-=d;
        while (d) {
            if(pq.empty()) break;
            pair<ll,ll> p=pq.top();
            pq.pop();
            ll tmp=min(d,b[p.second]);
            d-=tmp;
            b[p.second]-=tmp;
            if(b[p.second]) pq.push(p);
        }
        if(b[pos[now].second]==0&&!q[pos[now].second].empty()) {
            pq.push({q[pos[now].second].front(),pos[now].second});
            q[pos[now].second].pop();
        }
        sum+=bmx[pos[now].second]-b[pos[now].second];
        b[pos[now].second]=bmx[pos[now].second];
        last=pos[now].first;
    }
    
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    cin>>t;
    while (t--) {
        solve();
    }
    return 0;
}

详细

Test #1:

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

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

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'