제출 #529865

#제출 시각아이디문제언어결과실행 시간메모리
529865__VariattoDetecting Molecules (IOI16_molecules)C++17
0 / 100
0 ms204 KiB
#include <bits/stdc++.h> #include "molecules.h" using namespace std; #define pb push_back #define fi first #define se second #define ll long long const ll MAX=2e5+10; pair<ll,ll>t[MAX]; ll n, u, l; vector<ll>v; ll pref[MAX], suf[MAX]; vector<int> znajdz(ll k){ ll sum=pref[k-1]; vector<int>wy; for(ll i=0; i<k; i++) wy.pb(t[i].se); if(sum>=l && sum<=u) return wy; for(ll i=0; i<k; i++){ sum-=t[i].fi, sum+=t[n-i-1].fi; wy[i]=t[n-i-1].se; if(sum>=l && sum<=u) return wy; } return wy; } vector<int> find_subset(int l, int u, vector<int>w){ ll n=w.size(); for(ll i=0; i<n; i++){ t[i].fi=w[i]; t[i].se=i; } sort(t, t+n); for(ll i=0; i<n; i++){ pref[i]=t[i].fi; if(i) pref[i]+=pref[i-1]; } vector<int>wy; for(ll i=n-1; i>=0; i--) suf[i]=suf[i+1]+t[i].fi; for(ll k=1; k<=n; k++){ if(pref[k-1]<=u && suf[n-k]>=l){ wy=znajdz(k); sort(wy.begin(), wy.end()); return wy; } } return wy; } /*int main(){ ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin>>n>>l>>u; vector<ll>x; for(ll i=1; i<=n; i++){ ll c=0; cin>>c; x.pb(c); } vector<ll>xd=find_subset(l, u, x); for(auto a:xd) cout<<a<<" "; cout<<"\n"; }*/
#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...