# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1050753 | 2024-08-09T13:56:47 Z | vqpahmad | Detecting Molecules (IOI16_molecules) | C++14 | 0 ms | 0 KB |
#include "molecules.h" #include<bits/stdc++.h> using namespace std; #ifdef ONPC #include"debug.h" #else #define debug(...) 42 #endif #define endl '\n' #define ll long long #define pii pair<int,int> #define F first #define S second #define pb push_back #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } const int mod = 1e9 + 7; const int MAXN = 1e6 + 15; const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; vector<int> find_subset(int l, int u, vector<int> w) { vector<pii> a(n); for (int i = 0; i < sz(w); i++) a[i] = {w[i], i}; sort(all(a)); deque<int> dq; int cur = 0; bool ok = 0; for (int i = 0; i < sz(a) && !ok; i++){ if (cur + a[i].F <= u) { dq.pb(a[i].S); cur += a[i].F; } else if (sz(dq)){ cur -= w[dq.front()]; dq.pop_front(); dq.pb(a[i].S); cur += a[i].F; } ok |= (cur >= l && cur <= u); } vector<int> ans; if (ok){ for (auto it : dq) ans.pb(it); } return ans; }