QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#678337#9528. New Energy Vehicleucup-team5234#WA 0ms3604kbC++172.4kb2024-10-26 14:41:002024-10-26 14:41:30

Judging History

This is the latest submission verdict.

  • [2024-10-26 14:41:30]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3604kb
  • [2024-10-26 14:41:00]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T> using VVVV = VV<VV<T>>;
#define rep(i,n) for(ll i=0ll;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)
const long long INF = (1LL << 60);
const long long mod99 = 998244353;
const long long mod107 = 1000000007;
const long long mod = mod99;
#define eb emplace_back
#define be(v) (v).begin(),(v).end()
#define all(i,v) for(auto& i : v)
#define UQ(v) sort(be(v)), v.erase(unique(be(v)), v.end())
#define LB(x,v) (lower_bound(be(v),(x))-(v).begin())
#define UB(x,v) (upper_bound(be(v),(x))-(v).begin())
#define dout()  cout << fixed << setprecision(20)
#define randinit() srand((unsigned)time(NULL))

template<class T, class U> bool chmin(T& t, const U& u) { if (t > u){ t = u; return 1;} return 0; }
template<class T, class U> bool chmax(T& t, const U& u) { if (t < u){ t = u; return 1;} return 0; }




void solve(){
    ll n,m;
    cin >> n >> m;
    V<ll> v(n), x(m), y(m);
    rep(i,n) cin >> v[i];
    rep(i,m) cin >> x[i] >> y[i];
    V<pair<ll,ll>> vv;
    VV<ll> k(n);
    rep(i, m){
        y[i]--;
        k[y[i]].eb(x[i]);
        vv.eb(x[i], y[i]);
    }
    rep(i, n) k[i].eb(INF);
    vv.eb(INF, -1);

    ll xx = 0;
    set<pair<ll,ll>> st;
    V<ll> idx(n, 0);
    rep(i, n) st.insert({k[i][0], i});
    V<ll> w = v;
    ll p = 0;
    while(!st.empty()){
        auto[nx, pre] = vv[p];
        // cout << xx << " " << nx << " " << pre << endl;
        if(nx == xx){
            p++;
            idx[pre]++;
            w[pre] = v[pre];
            st.insert({k[pre][idx[pre]], pre});
            continue;
        }
        auto[kk,rest] = *st.begin();
        // cout << kk << " " << rest << endl;
        st.erase(st.begin());
        if(kk != k[rest][idx[rest]]) continue;
        if(xx+w[rest] <= nx){
            xx += w[rest];
            w[rest] = 0;
        }else{
            w[rest] -= (nx - xx);
            xx = nx;
            st.insert({k[rest][idx[rest]], rest});
        }
        
    }
    cout << xx << endl;

}





int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t=1;
    cin >> t;
    rep(i,t) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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:

6
11
4
11
999999999
1000000000

result:

wrong answer 1st lines differ - expected: '9', found: '6'