Submission #1270497

#TimeUsernameProblemLanguageResultExecution timeMemory
1270497SnowRaven52Detecting Molecules (IOI16_molecules)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; vector<int> find_subset(long long l, long long u, const vector<int> & w) { int n = (int) w.size(); vector<pair<int, int>> a; for (int i = 0; i < n; i++) a.push_back({ w[i], i }); sort(a.begin(), a.end()); long long s = 0; int i = 0; for (int j = 0; j < n; j++) { s += a[j].first; while (s > u && i <= j) { s -= a[i].first; i++; } if (l <= s && s <= u) { vector<int> ans; for (int k = i; k <= j; k++) ans.push_back(a[k].second); return ans; } } return {}; } int main() { // freopen("main.in", "r", stdin); // freopen(".out", "w", stdout); ios::sync_with_stdio(false); cin.tie(nullptr); int n; long long l, u; cin >> n >> l >> u; vector<int> w(n); for (int i = 0; i < n; i++) cin >> w[i]; vector<int> ans = find_subset(l, u, w); cout << (int) ans.size() << endl; if (!ans.empty()) { for (int i = 0; i < (int) ans.size(); i++) { if (i) cout << ' '; cout << ans[i]; } cout << endl; } }

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
      |         ^~~~
/usr/bin/ld: /tmp/ccCkaUmY.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc8b7fKg.o:molecules.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccCkaUmY.o: in function `main':
grader.cpp:(.text.startup+0x165): undefined reference to `find_subset(int, int, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status