#include <bits/stdc++.h>
#include "molecules.h"
using namespace std;
typedef long long ll;
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...); }
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
const int N = 1e4 + 3;
vector<int> ww;
bool cmp(int i, int j) {
return (ww[i] < ww[j]);
}
vector<int> find_subset(int l, int u, vector<int> w) {
ww = w;
vector<int> res(w.size());
for (int i = 0; i < w.size(); i++) res[i] = i;
sort(res.begin(), res.end(), cmp);
int suml = 0, sumr = 0;
for (int i = 0; i < w.size(); i++) {
int rr = w.size()-1-i;
suml += w[res[i]], sumr += w[res[rr]];
if (suml <= u && sumr >= l) {
vector<int> ans;
int t = w.size()-1, p = 0;
while (sumr > u && p < rr) {
ans.push_back(res[p++]);
sumr -= w[res[t--]];
}
for (int j = rr; j <= t; j++)
ans.push_back(res[j]);
sort(ans.begin(), ans.end());
return ans;
}
}
return {};
}
Compilation message (stderr)
molecules.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
molecules_c.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
# | 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... |