| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1265475 | gustavo_d | Detecting Molecules (IOI16_molecules) | C++20 | 1095 ms | 2632 KiB | 
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e5;
pair<int, int> sortedW[MAXN];
vector<int> find_subset(int l, int r, vector<int> w) {
    int n = (int)w.size();
    for (int i=0; i<n; i++) sortedW[i] = {w[i], i};
    sort(sortedW, sortedW + n);
    for (int k=1; k<=n; k++) {
        ll sum1 = 0, sum2 = 0;
        for (int i=0; i<k; i++) sum1 += sortedW[i].first;
        for (int i=1; i<=k; i++) sum2 += sortedW[n-i].first;
        vector<int> res;
        if (l <= sum1 and sum1 <= r) {
            for (int i=0; i<k; i++) res.push_back(sortedW[i].second);
        }
        if (sum1 <= l and sum2 >= l and res.empty()) {
            for (int pt=1; pt<=k; pt++) {
                sum1 += sortedW[n-pt].first - sortedW[k-pt].first;
                if (l <= sum1 and sum1 <= r) {
                    for (int i=0; i<k-pt; i++) res.push_back(sortedW[i].second);
                    for (int i=1; i<=pt; i++) res.push_back(sortedW[n-i].second);
                    break;
                }
            }
        }
        if (!res.empty()) return res;
    }
    return vector<int>(0);
}
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... | ||||
