# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
524746 | vijay | 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 <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <bitset>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
#define trav(a, x) for (auto& a: x)
#define all(x) begin(x), end(x)
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define NUM(a) (sizeof(a)/sizeof(*a))
vector<int> find_subset(int l, int u, vector<int> w){
vector<int> result;
int n = w.size();
vector<pair<int, int> > a(n, pair<int, int>());
for(int i = 0; i < n; i++){
a[i] = mp(w[i], i);
}
sort(a.begin(), a.end());
//
// for(int i = 0; i < n; i++){
// cout << a[i].f << " " << a[i].s << "\n";
// }
vector<int> minSum(n + 1, 0);
vector<int> maxSum(n + 1, 0);
for(int k = 1; k <= n; k++){
minSum[k] = minSum[k - 1] + a[k - 1].f;
maxSum[k] = maxSum[k - 1] + a[n - k].f;
}
for(int k = 1; k <= n; k++){
if(minSum[k] <= u && maxSum[k] >= l){
// this could fit within the range!
// System.out.println("this could fit within the range! " + k);
int currSum = minSum[k];
int idx = k;
while(idx <= n){
if(currSum >= l && currSum <= u){
// System.out.println(k);
for(int i = idx - k; i < idx; i++){
result.pb(a[i].s);
}
return result;
}
if(idx == n){
break;
}
currSum += a[idx].f;
currSum -= a[idx - k].f;
idx++;
}
}
}
return result;
}
int main(){
// ios_base::sync_with_stdio(0);
// cin.tie(0);
// vector<int> tc;
// tc.pb(6);tc.pb(8);tc.pb(8);tc.pb(7);
// vector<int> v = find_subset(15, 17, tc);
// for(auto& a: v){
// cout << a << "\n";
// }
}