Submission #416882

#TimeUsernameProblemLanguageResultExecution timeMemory
416882Emin2004Detecting Molecules (IOI16_molecules)C++14
100 / 100
153 ms15140 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pii pair<ll, int> #define F first #define S second const int N = 200005; const int mod = 1e9+7; bool cmp(pii a, pii b){ return a.F < b.F; } vector<int> find_subset(int l, int u, vector<int> w) { pii a[N]; int n = 0; for(int i : w){ a[n] = {i, n}; n++; } sort(a, a + n, cmp); set<int> s; vector<int> ans; ll sum = 0, p1 = 0, p2 = 0; while(p2 != n && p1 != n){ while(sum < l){ sum += a[p1].F; s.insert(a[p1].S); p1++; if(p1 == n) break; } while(sum > u){ sum -= a[p2].F; s.erase(s.find(a[p2].S)); p2++; if(p2 == n) break; } if(sum >= l && sum <= u){ while(s.size() > 0){ ans.pb(*s.begin()); s.erase(s.begin()); } break; } } return ans; }
#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...