# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
711922 | thimote75 | Detecting Molecules (IOI16_molecules) | C++14 | 52 ms | 5552 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>
#include "molecules.h"
using namespace std;
#define di pair<int, int>
#define idata vector<int>
#define ddata vector<di>
#define num long long
idata find_subset(int l, int u, idata weights) {
int n = weights.size();
ddata wi_data(n);
for (int i = 0; i < n; i ++)
wi_data[i] = { weights[i], i };
sort(wi_data.begin(), wi_data.end());
for (int i = 0; i < n; i ++)
weights[i] = wi_data[i].first;
num p_sum = 0;
num s_sum = 0;
int h;
for (h = 0; h < weights.size(); h ++) {
p_sum += weights[h];
s_sum += weights[n - 1 - h];
if (p_sum <= u && s_sum >= l) break ;
}
h ++; // Here h is the size of the data
if (!(p_sum <= u && s_sum >= l))
return idata(0);
num c_sum = 0;
int index;
for (index = 0; index < n; index ++) {
c_sum += weights[index];
if (index - h >= 0) c_sum -= weights[index - h];
if (index + 1 >= h && l <= c_sum && c_sum <= u)
break ;
}
idata res (h);
for (int i = 0; i < h; i ++)
res[i] = wi_data[index - i].second;
return res;
}
/*int main () {
int n, l, u;
cin >> n >> l >> u;
idata w (n);
for (int i = 0; i < n; i ++)
cin >> w[i];
idata res = find_subset(l, u, w);
cout << res.size() << endl;
for (int i = 0; i < res.size(); i ++)
cout << res[i] << " ";
}*/
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... |