# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
196924 | Swan | Detecting Molecules (IOI16_molecules) | C++14 | 0 ms | 0 KiB |
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 <bits/stdc++.h>
#include "molecules.h"
#define stop system("pause")
#define stop2 char o; cin >> o
#define INP freopen("cowrect.in","r",stdin)
#define OUTP freopen ("cowrect.out","w",stdout)
#define int long long
using namespace std;
vector<int> find_subset(int l, int u, vector<int> w) {
vector<pair<int,int> > start;
for(int i(0); i < w.size();i++){
start.push_back({w[i],i});
}
sort(start.begin(),start.end());
sort(w.begin(),w.end());
if(w[0] > u)return {};
int res = 0;
for(int i(0); i < w.size();i++){
res+=w[i];
}
if(res < l)return {};
if(res>=l && res<=u){
return w;
}
res = 0;
set<pair<int,int> > s;
int cnt = 0;
int pnt = 0;
for(int i(0); i < w.size();i++){
if(res + w[i] > u)break;
res+=w[i];
cnt++;
s.insert({w[i],i});
pnt++;
}
//cout << res << ' ' << cnt << endl;
vector<int> v;
while(cnt){
int now = s.begin()->first;
res-=now;
res+=w[pnt];
s.erase(s.begin());
s.insert({w[pnt],pnt});
pnt++;
cnt--;
//cout << res << ' ' << l << ' ' << u << endl;
if(pnt == w.size())break;
if(res>=l && res <=u){
int pnt = 0;
for(auto& a: s)v.push_back(start[a.second].second);
break;
}
}
//cout << res << endl;
return v;
}
/*
main(){
ios_base::sync_with_stdio(0);
int l,u,n; cin >> l >> u >> n;
vector<int> v;
for(int i(0); i < n;i++){
int x; cin >> x;
v.push_back(x);
}
vector<int> ans = find_subset(l,u,v);
for(int i(0); i < ans.size();i++)cout << ans[i] << ' ';
return 0;
}*/
/*
15 17 4
6 8 8 7
14 15 4
5 5 6 6
10 20 4
15 17 16 18
*/