This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "molecules.h"
#include "molecules.h"
#include<bits/stdc++.h>
using namespace std;
vector<int> getAns(vector<pair<int, int> > aux, int ini, int fim);
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
int n = w.size();
vector<int> ret;
vector<pair<int, int> > aux;
for(int i = 0; i < w.size(); i++)
aux.push_back(make_pair(w[i], i));
sort(aux.begin(), aux.end());
vector<int> suf, pref;
suf.push_back(aux[0].first);
pref.push_back(aux[n - 1].first);
for(int i = 1; i < n; i++)
suf.push_back(suf[suf.size() - 1] + aux[i].first);
for(int i = n - 2; i >= 0; i--)
pref.push_back(pref[pref.size() - 1] + aux[i].first);
if(suf[n - 1] < l) return ret;
if(suf[0] > u) return ret;
if(suf[n - 1] <= u) return getAns(aux, n - 1, n - 1);
for(int i = 0; i < n; i++){
if(suf[i] > u) break;
if(suf[i] >= l) return getAns(aux, i, n + 1);
int k = lower_bound(pref.begin(), pref.end(), l - suf[i]) - pref.begin();
if(k == pref.size()) continue;
if(k + 1 + i + 1 > n) continue;
if(suf[i] + pref[k] > u) continue;
if(suf[i] + pref[k] < l) continue;
k = n - 1 - k;
if(k <= i) continue;
return getAns(aux, i, k);
}
int k = lower_bound(pref.begin(), pref.end(), l) - pref.begin();
if(k == pref.size()) return ret;
if(pref[k] > u) return ret;
if(pref[k] < l) return ret;
k = n - 1 - k;
return getAns(aux, -1, k);
}
vector<int> getAns(vector<pair<int, int> > aux, int ini, int fim){
vector<int> ret;
for(int i = 0; i <= ini; i++)
ret.push_back(aux[i].second);
for(int i = aux.size() - 1; i >= fim; i--)
ret.push_back(aux[i].second);
sort(ret.begin(), ret.end());
return ret;
}
Compilation message (stderr)
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:13:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | for(int i = 0; i < w.size(); i++)
| ~~^~~~~~~~~~
molecules.cpp:36:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | if(k == pref.size()) continue;
| ~~^~~~~~~~~~~~~~
molecules.cpp:47:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | if(k == pref.size()) return ret;
| ~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |