#include <bits/stdc++.h>
#include "molecules.h"
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
#define MOO(i, a, b) for(int i=a; i<b; i++)
#define M00(i, a) for(int i=0; i<a; i++)
#define MOOd(i,a,b) for(int i = (b)-1; i >= a; i--)
#define M00d(i,a) for(int i = (a)-1; i>=0; i--)
#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _ << " _ " <<
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ld,ld> pd;
typedef complex<ld> cd;
vi find_subset(int l, int u, vi w) {
vi ws;
for(int x: w) ws.pb(x);
sort(all(ws));
ll least = 0;
ll most = 0;
vi res;
for(int cnt = 1; cnt <= sz(ws); cnt++) {
least += ws[cnt-1];
most += ws[sz(ws)-cnt];
if(l <= least && least <= u) {
for(int j = 0; j < cnt; j++) {
res.pb(ws[j]);
}
break;
} else if(l <= most && most <= u) {
for(int j = sz(ws)-cnt; j < sz(ws); j++) {
res.pb(ws[j]);
}
break;
} else if(least < l && u < most) {
ll tot = least;
int idx = 0;
while(tot < l) {
tot -= ws[cnt-1-idx];
tot += ws[sz(ws)-1-idx];
idx++;
}
for(int j = 0; j < cnt-idx; j++) {
res.pb(ws[j]);
}
for(int j = sz(ws)-1; j >= sz(ws)-idx; j--) {
res.pb(ws[j]);
}
break;
}
}
if(sz(res) == 0) return res;
int cnt = 0;
for(int x: res) cnt += x;
assert(l <= cnt && cnt <= u);
multiset<int> inAns;
for(int x: res) inAns.insert(x);
vi ans;
M00(i, sz(w)) {
if(inAns.count(w[i])) {
ans.pb(i+1);
inAns.erase(inAns.find(w[i]));
}
}
return ans;
}
/*int main() { FAST
int l, u; cin >> l >> u;
int n; cin >> n;
vi v; M00(i, n) {
int x; cin >> x;
v.pb(x);
}
vi ans = find_subset(l,u,v);
for(int i: ans) cout << i << " "; cout << "\n";
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
4 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
4 ms |
256 KB |
Integer 1 violates the range [0, 0] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
OK (n = 12, answer = YES) |
2 |
Correct |
4 ms |
256 KB |
OK (n = 12, answer = YES) |
3 |
Correct |
5 ms |
256 KB |
OK (n = 12, answer = NO) |
4 |
Correct |
5 ms |
384 KB |
OK (n = 12, answer = NO) |
5 |
Incorrect |
5 ms |
256 KB |
sum of weights should be in [290..300] but it is 301 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
4 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
4 ms |
256 KB |
Integer 1 violates the range [0, 0] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
4 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
4 ms |
256 KB |
Integer 1 violates the range [0, 0] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
4 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
4 ms |
256 KB |
Integer 1 violates the range [0, 0] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
4 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
4 ms |
256 KB |
Integer 1 violates the range [0, 0] |
4 |
Halted |
0 ms |
0 KB |
- |