# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1115316 | komasan | 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<bits/stdc++.h>
using namespace std;
using i64 = long long;
using u32 = unsigned;
using u64 = unsigned long long;
#define fi first
#define se second
template<class A, class B> inline bool maximize(A& x, B y) {
if (x < y) {
x = y;
return true;
} else
return false;
};
template<class A, class B> inline bool minimize(A& x, B y) {
if (x > y) {
x = y;
return true;
} else
return false;
};
vector<int> find_subset(int l, int r, vector<int> a) {
vector<pair<int, int>> p;
for (int i = 0; i < a.size(); i++)
p.push_back(make_pair(a[i], i + 1));
sort(p.begin(), p.end());
int sum = 0, j = 0;
for (int i = 0; i < (int)a.size(); i++) {
sum += p[i].fi;
while (sum > r)
sum -= p[j++].fi;
if (sum >= l) {
vector<int> ans;
for (int k = j; k <= i; k++)
ans.push_back(p[k].se);
sort(ans.begin(), ans.end());
return ans;
}
}
return {};
}
void komasan() {
vector<int> ans = find_subset(15, 17, {6, 8, 8, 7});
for (int x : ans)
cout << x << ' ';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen(".inp", "r", stdin);
// freopen(".out", "w", stdout);
komasan();
}