Submission #886441

# Submission time Handle Problem Language Result Execution time Memory
886441 2023-12-12T07:25:10 Z vjudge1 Gym Badges (NOI22_gymbadges) C++17
0 / 100
2000 ms 24656 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e9;

/*
struct segtree{
    int n;
    vector<int> st, t, marked;
    vector<array<int, 2>> x;

    int base = 0;

    segtree(int _n){
        n = _n;
        st.resize(4*n, 0);
        t.resize(4*n, 0);
        marked.resize(4*n, 0);
        x.resize(4*n, 0);
    }

    void update(int v, int l, int r, int val){
        push(v, l, r);
        if(l>tr || r <tl) return;
        if(l>=tl && r<=tr){
            st[v]+=val; t[v] =val;
            marked[v] = 1;
        }
        else{
            int mid = (l+r) / 2;
            update(v*2, l, mid, val);
            update(v*2, mid, l, 1);
        }
    }


}
*/
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);


    int n; cin >> n;
    vector<int> l(n), x(n);

    for(int i=0; i<n; i++) cin >> x[i];
    for(int i=0; i<n; i++) cin >> l[i];

    vector<int> ans(n+1, -1), ind(n+1, -1);
    
    ans[0] = 0;

    int pos = 0;

    for(int i=0; i<n; i++){
        vector<int>pref;
        pref = ans;

        for(int l=1; l<=pos; l++){
            pref[l]+=pref[l-1];
        }

        if(pref[pos] <= l[i]){
            ans[pos+1] = x[i];
            ind[pos+1] = i;
            pos++;
        }
        else{
            int pf = -1;
            for(int j=0; j<pos&&pf==-1; j++){
                if(pref[j] <= l[i] && ans[j+1] > x[i]) pf = j;
            }
            int el = i;
            int sum = pref[pos];


            while(pf!=-1){
                int tmp = ind[pf+1];
                ans[pf+1] =x[el];
                ind[pf+1] = el;
                sum = sum+x[el]-x[tmp];
                el = tmp;
                pf = -1;

                for(int j=0; j<pos&&pf==-1; j++){
                    if(pref[j] <= l[i] && ans[j+1] > x[el]) pf = j;
                }
            }

            sum+= x[el];
            for(int j=1; j<=pos; j++){
                if(sum-x[ind[j]]<=l[ind[j]]){
                    int tmp = ind[j];
                    ans[j] = x[el];
                    ind[j] = el;
                    el = tmp;
                }
            }

            if(sum-x[el] <=l[el]){
                ans[pos+1] = x[el];
                ind[pos+1] = el;
                pos++;
            }
        }
    }

    cout << pos;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2092 ms 24656 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -