제출 #658064

#제출 시각아이디문제언어결과실행 시간메모리
658064kussssoDetecting Molecules (IOI16_molecules)C++17
69 / 100
46 ms6528 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; vector<int> find_subset (int l, int u, vector<int> w) { vector<int> res; vector<pair<int, int>> v; int n = w.size(); for (int i = 0; i < n; i++) { v.push_back({w[i], i}); } sort(v.begin(), v.end()); vector<int> pf(n, 0); vector<int> sf(n + 1, 0); for (int i = 0; i < n; i++) { pf[i] = (i == 0 ? 0 : pf[i - 1]) + v[i].first; } for (int i = n - 1; i >= 0; i--) { sf[i] = sf[i + 1] + v[i].first; } for (int len = 1; len <= n; len++) { if (pf[len - 1] >= l or sf[n - len] >= l) { if (pf[len - 1] > u) return {}; for (int i = 0; i + len - 1 < n; i++) { int sum = pf[i + len - 1] - (i == 0 ? 0 : pf[i - 1]); if (l <= sum and sum <= u) { for (int j = i; j < i + len; j++) { res.push_back(v[j].second); } return res; } } } } 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...