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 F first
#define S second
#define P push
#define pb push_back
#define MEM(dp,i) memset(dp,i,sizeof(dp))
#define W while
#define R return
#define C continue
#define SI size()
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define SF(x) scanf("%I64d",&x)
#define SF2(x,y) scanf("%I64d%I64d",&x,&y)
#define SF3(x,y,z) scanf("%I64d%I64d%I64d",&x,&y,&z)
#define SF4(x,y,z,o) scanf("%I64d%I64d%I64d%I64d",&x,&y,&z,&o)
#define all(v) v.begin(),v.end()
using namespace std;
const long long INF = 1e9;
const int MX=1000005;
vector<int> r1,r2,res;
vector<pii> v;
vector<int> find_subset(int l, int u, vector<int> w) {
for(int i=0;i<w.SI;i++){
v.pb({w[i],i});
}
sort(all(v));
int sum=0;
for(int i=w.SI-1;sum<l&&i>=0;i--){
sum+=v[i].F;
r1.pb(v[i].S);
}
for(int i=0;i<w.SI-r1.SI;i++){
r2.pb(v[i].S);
}
reverse(all(r2));
reverse(all(r1));
W(sum>u){
if(r1.empty()||r2.empty())R vector<int>(0);
sum-=w[r1.back()];
// cout<<r1.back()<<" ";
r1.pop_back();
res.pb(r2.back());
sum+=w[r2.back()];
// cout<<r2.back()<<endl;
r2.pop_back();
}
W(!r1.empty()){
res.pb(r1.back());
r1.pop_back();
}
return res;
}
Compilation message (stderr)
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:29:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<w.SI;i++){
^
molecules.cpp:38:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<w.SI-r1.SI;i++){
^
# | 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... |