# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1105886 | abushbandit_ | Detecting Molecules (IOI16_molecules) | C++17 | 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 "molecules.h"
#include "bits/stdc++.h"
using namespace std;
#define int long long
vector<int> find_subset(int a, int b, vector<int> w) {
vector<pair<int,int>> w2;
int j = 1;
for(auto i : w) w2.push_back({i,j++});
sort(w.begin(),w.end());
sort(w2.begin(),w2.end());
int n = w.size();
int resr = 0,resl = n;
int l = 0;
int ans = 0;
int sum = 0;
for(int r = 0;r < n;r++) {
sum += w[r];
if(sum < a) {
continue;
}
while(sum > b && l <= r) {
sum -= w[l];
l++;
}
if(sum >= a && sum <= b) {
if(ans < r - l + 1) {
ans = r - l + 1;
resr = r,resl = l;
}
}
}
vector<int> res;
for(int i = resl;i <= resr;i++) {
res.push_back(w2[i].second - 1);
}
return res;
}