QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#687484#9528. New Energy VehicleTANGTANGCCWA 49ms13520kbC++232.6kb2024-10-29 19:16:512024-10-29 19:16:55

Judging History

This is the latest submission verdict.

  • [2024-10-29 19:16:55]
  • Judged
  • Verdict: WA
  • Time: 49ms
  • Memory: 13520kb
  • [2024-10-29 19:16:51]
  • 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],del[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];
            del[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(del[bh]) {
                    st.pop();
                    continue;
                }
                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];
                del[tar]=1;
            }
            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: 0ms
memory: 7940kb

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

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: 49ms
memory: 13520kb

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:

1543020
1578939
1474636
1527381
1547404
1564631
1051729
1548178
1114634
1072253

result:

wrong answer 3rd lines differ - expected: '1526016', found: '1474636'