Submission #1258296

#TimeUsernameProblemLanguageResultExecution timeMemory
1258296sohamsen15Detecting Molecules (IOI16_molecules)C++20
69 / 100
34 ms4028 KiB
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> find_subset(int low, int high, vector<int> w) {
    vector<pair<int, int>> a; 
    for (int i = 0; i < w.size(); i++) a.push_back({ w[i], i });
    sort(a.begin(), a.end());
    int l = 0, r = 0, n = a.size(), s = a[0].first; bool done = false;
    while (r < n) {
        if (s >= low && s <= high) {
            done = true;
            break;
        }

        if (s > high) s -= a[l].first, l++;
        else r++, s += a[r].first;
    }
    if (!done) return vector<int>(0);

    vector<int> ans;
    for (int i = l; i <= r; i++) ans.push_back(a[i].second);
    sort(ans.begin(), ans.end());
    return ans;
}

// int main() {
//     vector<int> ans = find_subset(10, 20, {15, 17, 16, 18});
//     for (auto x: ans) cout << x << " ";
// }

Compilation message (stderr)

molecules.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
molecules_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...