이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 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... |