# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
500722 | aryan12 | Detecting Molecules (IOI16_molecules) | C++17 | 51 ms | 8204 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 "molecules.h"
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
return a.first < b.first;
}
vector<int> find_subset(int l, int r, vector<int> w) {
vector<pair<long long, long long> > a;
for(long long i = 0; i < w.size(); i++) {
a.push_back(make_pair(w[i], i));
}
sort(a.begin(), a.end(), cmp);
long long left = 0, right = 0, sum = a[0].first;
for(long long i = 1; i < a.size(); i++) {
sum += a[i].first;
if(sum > r) {
break;
}
right = i;
}
vector<int> ans;
if(sum >= l && sum <= r) {
for(long long i = 0; i <= right; i++) {
ans.push_back(a[i].second);
}
}
else {
int f = 0;
sum = 0;
left = 0, right = -1;
int x = a.size() - 1;
for(left = 0; left < a.size(); left++) {
if(left != 0) sum -= a[left - 1].first;
//cout << "right = " << right << ", a.size() - 1 = " << a.size() - 1 << ", sum + a[right + 1].first = " << sum + a[right + 1].first << ", r = " << r << "\n";
while(right < x && sum + a[right + 1].first <= r) {
//cout << "party all night\n";
right++;
sum += a[right].first;
}
//cout << "left = " << left << ", right = " << right << "\n";
if(sum >= l && sum <= r) {
f = 1;
break;
}
}
if(f == 1) {
for(long long i = left; i <= right; i++) {
ans.push_back(a[i].second);
}
}
}
return ans;
}
Compilation message (stderr)
# | 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... |