제출 #1007950

#제출 시각아이디문제언어결과실행 시간메모리
1007950ProtonDecay314Detecting Molecules (IOI16_molecules)C++17
9 / 100
1 ms348 KiB
/*
5, 5, 6, 6


0, 0, 1, 1
1, 1, 2, 2

15, 10, 5, -1, -7
1,  2,  2, 1,  1

[14, 15]
[8, 10],
[3, 5],
[-2, -1],
[-8, -7]

15, 17

[6, 8, 8, 7]

2, 2, 1, 0

17, 11, 4, -4, -12
2,  4,  4, 3,  2
?,  8,  8, 7,  6

[4, 0]

[15, 17]
[7, 11],
[0, 4],
[-7, -4],
[-14, -12],

[0, 1]
[6, 8]
[13, 14]

0, 2, 2, 1, 0
[0, 2],
[6, 10],
[13, 17],
[21, 24],
[29, 31]

10, 20

20, 

---
[6, 9, 9]

[15, 18]

0, 3, 3, 0

[0, 3],
[6, 12],
[15, 21],
[24, 27]
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
#define fi first
#define se second

vi find_subset(int l, int u, vi wint) {
    ll n = wint.size();
    vpll w;
    for(ll i = 0; i < n; i++) {
        w.push_back({wint[i], i});
    }

    sort(w.begin(), w.end());

    vll lb(n + 1, 0ll);
    for(ll i = 0; i < n; i++) {
        lb[i + 1] = lb[i] + w[i].fi;
    }

    vll ub(n + 1, 0ll);
    ub[0] = u - l;

    for(ll i = 0; i < n; i++) {
        ub[i + 1] = lb[i + 1] + w[n - i - 1].fi - w[0].fi + u - l;
        #ifdef DEBUG
        cout << ub[i + 1] << endl;
        #endif
    }

    ll cur_int_ind = 0ll;

    while(cur_int_ind < n + 1 && !(lb[cur_int_ind] <= u && u <= ub[cur_int_ind])) {
        cur_int_ind++;
    }

    // No interval found
    if(cur_int_ind == n + 1) return {};

    ll p2 = n - 1;

    vi inds;

    ll cur_sum = u;

    while(cur_int_ind > 0 && p2 >= 0) {
        while(p2 >= 0 && cur_sum - w[p2].fi < lb[cur_int_ind - 1]) p2--;
    
        cur_sum -= w[p2].fi;
        cur_int_ind--;
        inds.push_back(w[p2].se);
        p2--;
    }



    // #ifdef DEBUG
    // return vector<int>(vals.begin(), vals.end());
    // #endif

    return inds;
}

// Driver function
#ifdef DEBUG
int main() {
    ll n, l, u;
    cin >> n >> l >> u;

    vi w(n, 0ll);
    for(int& wv : w) {
        cin >> wv;
    }

    vi ans = find_subset(l, u, w);

    for(int i : ans) {
        cout << i << " ";
    }
    cout << endl;

    return 0;
}
#endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...