제출 #252427

#제출 시각아이디문제언어결과실행 시간메모리
252427yuma220284Detecting Molecules (IOI16_molecules)C++14
100 / 100
66 ms8320 KiB
#include "molecules.h" #include <algorithm> using namespace std; std::vector<int> find_subset(int L, int U, std::vector<int> W) { int N = W.size(); vector<pair<long long, int> > V(N); for (int i = 0; i < N; i++) V[i] = { W[i], i }; sort(V.begin(), V.end()); vector<long long> Left(N + 1), Right(N + 1); Left[0] = 0; for (int i = 0; i < N; i++) Left[i + 1] = Left[i] + V[i].first; Right[N] = 0; for (int i = N - 1; i >= 0; i--) Right[i] = Right[i + 1] + V[i].first; reverse(Right.begin(), Right.end()); for (int i = 0; i <= N; i++) { long long X = L - Left[i]; int Y = lower_bound(Right.begin(), Right.end(), X) - Right.begin(); if (i + Y > N) continue; if (Left[i] + Right[Y] <= U) { vector<int> ANS; for (int j = 0; j < i; j++) ANS.push_back(V[j].second); for (int j = 0; j < Y; j++) ANS.push_back(V[N - 1 - j].second); sort(ANS.begin(), ANS.end()); return ANS; } } return {}; }
#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...