Submission #51646

#TimeUsernameProblemLanguageResultExecution timeMemory
51646ernestvwDetecting Molecules (IOI16_molecules)C++11
Compilation error
0 ms0 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; bool cmp(pair<long long, long long> a, pair<long long, long long> b) { return (a.first == b.first ? a.second < b.second : a.first < b.first); } vector<int> find_subset(int l, int u, vector<int> w) { vector<pair<long long, int>> W; vector<int> V; int n = (int)w.size(); for(int i = 0; i < n; i++) W.push_back({w[i], i}); sort(W.begin(), W.end(), cmp); long long mini = 0, maxi = 0; int I = 0; for(int i = 0; i < n; i++, I++) { mini += W[i].first; maxi += W[n - 1 - i].first; if((l <= maxi and maxi <= u) or (l <= mini and mini <= u) or (mini <= l and u <= maxi)) break; } if(I == n) return V; int j = 0; for(j = 0; j <= I; j++) V.push_back(j); while(mini < l) { if(V[I] == n - (j - I)) I--; mini -= W[V[I]].first; V[i] = n - (j - I); mini += W[V[I]].first; } for(int i = 0; i < (int)V.size(); i++) V[i] = W[V[i]].second; return V; }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:29:7: error: 'i' was not declared in this scope
     V[i] = n - (j - I);
       ^