Submission #649985

#TimeUsernameProblemLanguageResultExecution timeMemory
649985tvladm2009Detecting Molecules (IOI16_molecules)C++14
100 / 100
43 ms4940 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2 * 1e5 + 7; int ind[N]; bool vis[N]; vector<int> find_subset(int l, int u, vector<int> w) { int n = w.size(); for (int i = 0; i < n; i++) { ind[i] = i; } sort(ind, ind + n, [&](int x, int y) -> bool { return w[x] < w[y]; }); vector<int> sol; ll sum1 = 0, sum2 = 0; for (int i = 0; i < n; i++) { vis[ind[i]] = true; sum1 += w[ind[i]]; sum2 += w[ind[n - i - 1]]; if (sum1 <= u && l <= sum2) { int ptr = 0; while (sum1 < l) { vis[ind[ptr]] = false; vis[ind[n - ptr - 1]] = true; sum1 -= w[ind[ptr]]; sum1 += w[ind[n - ptr - 1]]; ptr++; } for (int i = 0; i < n; i++) { if (vis[i] == true) { sol.push_back(i); } } return sol; } } return sol; }
#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...