Submission #404105

#TimeUsernameProblemLanguageResultExecution timeMemory
404105luisgalanDetecting Molecules (IOI16_molecules)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> #include "molecules.h" using namespace std; typedef long long int ll; #define debug(x) cerr << #x << " = " << (x) << endl vector<int> find_subset(int l, int u, vector<int> w) { int n = w.size(); vector<pair<int, int>> arr(n); for (int i = 0; i < n; i++) { arr[i] = { w[i], i }; } sort(arr.begin(), arr.end()); vector<ll> presum(n+1); for (int i = 0; i < n; i++) { presum[i + 1] = presum[i] + arr[i].first; } vector<int> ans; for (int k = 1; k <= n; k++) { int L = 0; int R = n - k + 1; while (L < R) { int m = (L + R) / 2; ll sum = presum[m + k] - presum[m]; if (sum < l) { L = m + 1; } else if (sum > u) { R = m; } else { debug(sum); for (int j = i; j < i + k; j++) { ans.push_back(arr[j].second); } break; } } if (!ans.empty()) break; } return ans; }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:31:30: error: 'i' was not declared in this scope
   31 |                 for (int j = i; j < i + k; j++) {
      |                              ^