QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#708247#9528. New Energy Vehiclewjynb666WA 78ms66220kbC++142.0kb2024-11-03 20:44:452024-11-03 20:44:45

Judging History

This is the latest submission verdict.

  • [2024-11-03 20:44:45]
  • Judged
  • Verdict: WA
  • Time: 78ms
  • Memory: 66220kb
  • [2024-11-03 20:44:45]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define  read_fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using ll=long  long;
using PII=pair<int,int>;
void solve(){
    int n,m;
    cin>>n>>m;
    //先写一个O(n^2)的贪心
    vector<int> a(n);
    
    
    for(int i=0;i<n;i++) cin>>a[i];
    vector<int> sq(a);
    vector<array<int,2>> b(m);
    
    for(int i=0;i<m;i++) cin>>b[i][0]>>b[i][1],b[i][1]--;
    sort(b.begin(),b.end());
    queue<int> nxt[n+1];
    for(int i=0;i<m;i++){
        nxt[b[i][1]].push(b[i][0]);
    }
    priority_queue<PII,vector<PII>,greater<PII>> q;//s中只维护邮箱里有油的的邮箱
    for(int i=0;i<n;i++){
        if(nxt[i].empty()) q.push({1e9+5,i});
        else q.push({nxt[i].front(),i});
    }    
        
    ll ans=0;
    int last=0;
    for(int i=0;i<m;i++){
        //依次去使用,后面的内容
        int need=b[i][0]-last;
        while(!q.empty()){
            auto t=q.top();
            //cerr<<t.first<<' '<<t.second<<"\n";
            q.pop();
            int res=min(need,a[t.second]);
            a[t.second]-=res;
            need-=res;
            ans+=res;
            if(a[t.second] && t.second!=b[i][1]) q.push({a[t.second],t.second});
            if(need==0) break;
        }
        //cerr<<"need="<<need<<"\n";
        //cerr<<"------\n";
        if(need>0) break;
        a[b[i][1]]=sq[b[i][1]];
        //第b[i][1]有油了,加上去,那它的位置是哪个呢?
        if(!nxt[b[i][1]].empty()) nxt[b[i][1]].pop();
        if(!nxt[b[i][1]].empty()) q.push({nxt[b[i][1]].front(),b[i][1]});
        else q.push({1e9+5,b[i][1]});
        last=b[i][0];
        
    }
    
    for(int i=0;i<n;i++){
        if(a[i]>0) {
            //cerr<<a[i]<<' ';
            ans+=a[i];
        }
    }
    //cerr<<"\n-------\n";
    cout<<ans<<'\n';
}


int main()
{
    read_fast;
    int t;
    cin>>t;
    while(t--) solve();
    return 0; 
}

詳細信息

Test #1:

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

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: 0
Accepted
time: 0ms
memory: 3612kb

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
4
11
999999999
2000000000

result:

ok 6 lines

Test #3:

score: -100
Wrong Answer
time: 78ms
memory: 66220kb

input:

10
230 8042
599 1039 69 1011 1366 824 14117 1523 806 5002 332 55 3769 996 359 1040 255 1135 3454 3609 6358 2509 3695 8785 3890 1304 3394 14611 33 89 2245 508 22 1043 10411 628 1279 714 903 585 7413 5099 845 148 4689 2110 8683 1613 143 3263 2599 110 244 3297 4742 1571 425 1822 15692 572 9397 328 1691...

output:

1517831
1578939
1526016
1527381
1517862
1550472
1051049
1539380
1114612
1072217

result:

wrong answer 1st lines differ - expected: '1543020', found: '1517831'