QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#687465#9528. New Energy VehicleTANGTANGCCWA 1ms5780kbC++232.4kb2024-10-29 19:10:232024-10-29 19:10:23

Judging History

This is the latest submission verdict.

  • [2024-10-29 19:10:23]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 5780kb
  • [2024-10-29 19:10:23]
  • Submitted

answer

//#pragma GCC optimize(1)
//#pragma GCC optimize(2)
//#pragma GCC optimize(3, "Ofast", "inline")

#include <bits/stdc++.h>

#define int long long
#define ld long double
#define i32 int
#define u32 unsigned int
#define i64 long long
#define u64 unsigned long long
#define u27 __int128
#define endl '\n'
#define VI vector<int>
#define VVI vector<VI>
#define rand() RANDOM(GEN)
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define CTM (cout<<"Time:"<<static_cast<double>(clock()-START_TIME)/CLOCKS_PER_SEC*1000<<"ms"<<endl)
typedef long long ll;

using namespace std;
random_device SEED;
mt19937_64 GEN(SEED());
uniform_int_distribution<u64> RANDOM(0, numeric_limits<u64>::max());
const clock_t START_TIME = clock();
const int N=1e5+50;
array<int,2> sz[N];
int dp[N],now[N],vis[N],drl[N];
signed main() {
#ifndef ONLINE_JUDGE
    freopen(".in", "r", stdin);
    freopen(".out", "w", stdout);
#endif
    IO;
    int tt;
    cin>>tt;
    while(tt--) {
        int res=0,ans=0;
        priority_queue<array<int,2>,vector<array<int,2>>,greater<>> st;
        int n,m;
        cin>>n>>m;
        vector<vector<int>> G(n+1);
        for (int i = 1; i <= n; ++i) {
            cin>>dp[i];
            drl[i]=dp[i];
            vis[i]=now[i]=0;
        }
        for (int i = 1; i <= m; ++i) {
            int a,b;
            cin>>a>>b;
            sz[i]={a,b};
            G[b].push_back(a);
            if(!vis[b]) {
                vis[b]=1;
                st.push({a,b});
            }
        }
        for (int i = 1; i <= n; ++i) {
            if(!vis[i]) res+=dp[i];
        }
        for (int i = 1; i <= m; ++i) {
            auto [dis,tar]=sz[i];
            dis-=ans;
            while(dis and !st.empty()) {
                auto [jl,bh]=st.top();
                if(dis>=dp[bh]) {
                    ans+=dp[bh],dis-=dp[bh];
                    dp[bh]=0;
                    st.pop();
                } else {
                    dp[bh]-=dis;
                    ans+=dis,dis=0;
                }
            }
            if(dis) {
                if(res>=dis) res-=dis,ans+=dis,dis=0;
                else break;
            }
            now[tar]++;
            if(now[tar]==G[tar].size()) res+=drl[tar];
            else st.push({G[tar][now[tar]],tar});
            dp[tar]=drl[tar];
        }
        cout<<ans+res<<endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

result:

wrong answer 2nd lines differ - expected: '11', found: '12'