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 <bits/stdc++.h>
using namespace std;
#define scd(t) scanf("%d", &t)
#define scld(t) scanf("%ld", &t)
#define sclld(t) scanf("%lld", &t)
#define scc(t) scanf("%c", &t)
#define scs(t) scanf("%s", t)
#define scf(t) scanf("%f", &t)
#define sclf(t) scanf("%lf", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long int li;
typedef unsigned long int uli;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;
vi find_subset(int l, int u, vi w)
{
int n = w.size();
sort(all(w));
vi out = {};
int id = 0;
int v = 0;
while (id < n && v <= u)
{
v += w[id];
out.pb(id);
id++;
}
if (v < l)
{
out = {};
return out;
}
else
{
if (v <= u)
{
return out;
}
id--;
v -= w[id];
out.pop_back();
int k = 0;
for (int i = n - 1; i >= id; i--)
{
if (v >= l)
break;
if (k >= out.size())
break;
v += w[i] - w[k];
out[k] = i;
k++;
}
if (v >= l && v <= u)
{
return out;
}
else
{
out = {};
return out;
}
}
}
// int main()
// {
// vi vec = {10, 10, 10};
// vi out = find_subset(10, 20, vec);
// for (auto e : out)
// cout << e << " ";
// }
Compilation message (stderr)
molecules.cpp: In function 'vi find_subset(int, int, vi)':
molecules.cpp:68:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | if (k >= out.size())
| ~~^~~~~~~~~~~~~
# | 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... |