Submission #729166

#TimeUsernameProblemLanguageResultExecution timeMemory
729166NintsiChkhaidzeDetecting Molecules (IOI16_molecules)C++17
100 / 100
53 ms7228 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define s second #include "molecules.h" using namespace std; const int N = 2e5 + 5; vector <pair <int,int> > a; long long p[N]; vector<int> find_subset(int L, int R, vector<int> w) { int n = w.size(); for (int i = 0; i < n; i++) a.pb({w[i],i}); sort(a.begin(),a.end()); for (int i= 0;i<n;i++){ p[i] = a[i].f; if (i) p[i] += p[i - 1]; } vector <int> ans; ans.clear(); for (int i =0;i<n;i++){ int l = i + 1,r = n - 1,res = i; while (l <= r){ int mid = (l + r)>>1; long long sum = p[mid]; if (i) sum -= p[i - 1]; if (sum >= L){ res = mid; r = mid - 1; } else{ l = mid + 1; } } long long s = p[res]; if (i) s-= p[i - 1]; if (L <= s && s <= R){ for (int j = i; j <= res; j++) ans.pb(a[j].s); return ans; } } 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...