Submission #1083955

#TimeUsernameProblemLanguageResultExecution timeMemory
1083955mindiyakDetecting Molecules (IOI16_molecules)C++14
69 / 100
33 ms5716 KiB
#include "molecules.h" #include <algorithm> #include <iostream> #define F first #define S second using namespace std; vector<int> find_subset(int l, int u, vector<int> w) { int n = w.size(); vector<pair<int,int>> arr(n); for(int i=0;i<n;i++)arr[i] = {w[i],i}; sort(arr.begin(),arr.end()); vector<int> pre(n+1,0); for(int i=1;i<=n;i++)pre[i] = pre[i-1] + arr[i-1].F; // for(int i=0;i<=n;i++)cerr << pre[i] << " "; // cerr << endl; // for(int i=0;i<n;i++)cerr << arr[i].F << " "; // cerr << endl; // for(int i=0;i<n;i++)cerr << arr[i].S << " "; // cerr << endl; int a = 0,b = 0; while(b<=n && a<=n){ // cerr << a << " " << b << " " << (pre[b] - pre[a]) << endl; if(pre[b] - pre[a] >= l && pre[b] - pre[a] <= u){ break; } else if(pre[b] - pre[a] < l)b++; else a++; } if(b == n+1 || a == n+1 || pre[b]-pre[a] < l || pre[b] - pre[a] > u)return vector<int>(); vector<int> ans; for(int i=a;i<b;i++)ans.push_back(arr[i].S); 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...