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 <vector>
#include <algorithm>
using namespace std;
vector<long long> s;
long long total;
int N;
vector<pair<int,int> > tmp;
int l,u;
vector<int> w;
long long sum(int small, int big){
return s[small] + total - s[N - big];
}
vector<int> output_vector(int small, int big, int position){
vector<int> v;
for (int i=0;i<small;i++) v.push_back(tmp[i].second);
if (position != -1) v.push_back(tmp[position].second);
for (int i=N-big;i<N;i++) v.push_back(tmp[i].second);
return v;
}
bool works(int small, int big, int position){
long long weight = sum(small, big) + (position != -1 ? w[position] : 0);
//printf("%d %d %d: %lld\n", small, big, position, weight);
if (l <= weight && weight <= u) return true;
return false;
}
std::vector<int> find_subset(int _l, int _u, std::vector<int> _w) {
l = _l;
u = _u;
w = _w;
total = 0;
N = w.size();
for (int i=0;i<N;i++) total += w[i];
tmp.assign(N, make_pair(-1,-1));
for (int i=0;i<N;i++){
tmp[i].first = w[i];
tmp[i].second = i;
}
sort(tmp.begin(), tmp.end());
for (int i=0;i<N;i++) w[i] = tmp[i].first;
s.assign(N + 1, 0);
s[0] = 0;
for(int i=0;i<N;i++) s[i + 1] = s[i] + w[i];
for (int count=1; count<=N; count++){
for (int left=count; left>0;left--){
for (int traveler=left-1;traveler<N - count + left; traveler++){
if (works(left - 1, count - left, traveler)) return output_vector(left - 1, count - left, traveler);
}
}
}
return std::vector<int>(0);
}
# | 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... |