제출 #810346

#제출 시각아이디문제언어결과실행 시간메모리
810346petezaDetecting Molecules (IOI16_molecules)C++14
31 / 100
2 ms724 KiB
#include <bits/stdc++.h> #include "molecules.h" using namespace std; vector<int> find_subset(int l, int u, vector<int> w) { int n = w.size(); if(accumulate(w.begin(), w.end(), 0ll) < l) return {}; int cr=0; long long cs = 0; vector<pair<int, int>> vec(n); for(int i=0;i<n;i++) vec[i] = {w[i], i}; sort(vec.begin(), vec.end()); deque<int> deq; while(cr < n && cs < l) { cs += vec[cr].first; deq.emplace_back(vec[cr++].second); } if(cs <= u) return vector<int>(deq.begin(), deq.end()); if(deq.empty() || cr == 0) exit(2); deq.pop_back(); cs -= vec[--cr].first; while(cr < n && cs < l) { cs += vec[cr].first; cs -= w[deq.front()]; deq.pop_front(); deq.emplace_back(vec[cr++].second); } if(cs < l) return {}; return vector<int>(deq.begin(), deq.end()); } /* int main() { vector<int> arr = {342, 234, 235, 454, 345, 234, 464, 123, 134}; auto res = find_subset(400, 800, arr); int sum = 0; for(int e:res)sum += arr[e]; for(int i=0;i<res.size();i++) cout << res[i] << ' '; cout << '\n' << sum ; }*/
#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...