This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define F first
#define S second
#define pb push_back
#define sz(x) (ll)x.size()
typedef vector <ll> vi;
typedef pair<ll,ll> ii;
typedef vector <ii> vii;
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define dbg2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl;
#define dbg3(x,y,z) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<" "<<#z<<": "<<z<<endl;
void printVct(vi &v){
for (ll i =0; i<sz(v); i++){
cout<<v[i]<<" ";
}
cout<<endl;
}
#define ins insert
ll s;
set <ll> st;
vi c;
void add(ll idx){
st.ins(idx);
s += c[idx];
}
void rem(ll idx){
st.erase(idx);
s -= c[idx];
}
vi find_subset(int l, int r, vi cc) {
c = cc;
vi mp(sz(c));
vii tmp(sz(c));
for (ll i =0; i<sz(c); i++){
tmp[i] = ii(c[i], i);
}
sort(tmp.begin(), tmp.end());
for (ll i =0; i<sz(c); i++){
mp[tmp[i].S] = i;
}
sort(cc.begin(),cc.end());
ll n = sz(c), p = 0; s = 0;
while (p < n && s < l){
add(p);
p++;
}
p--;
if (s < l){ //impossible to reach l
return vi();
}
if (s > r){
rem(p);
p--;
}
// dbg(p);
ll m = min(p, n-p-2);
p = 0;
// dbg2(s,m);
while (p <= m && s < l){
rem(p);
add(n-p-1);
p++;
}
if (s < l) return vi();
vi ans;
for (set <ll> :: iterator it = st.begin(); it != st.end(); it++){
ans.pb(mp[*it]);
}
return ans;
}
/*
4 15 17
6 8 8 7
10 50 51
8 9 9 8 9 8 9 8 8 8
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |