This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// https://oj.uz/problem/view/IOI16_molecules
// https://ioinformatics.org/files/ioi2016problem1.pdf
// #define GARY_DBG
#ifndef GARY_DBG
#include "molecules.h"
#endif
#include <bits/stdc++.h>
// #define int long long
constexpr int sizik = 1000 * 1001;
#define ar std::array
#define pr std::pair
#define vec std::vector
typedef vec<vec<int>> _kra;
std::vector<int32_t> find_subset(int l, int u, std::vector<int32_t> w) {
int n = (int)w.size();
std::vector<ar<int, 2>> local_w;
for (int i = 0; i < n; i++) {
local_w.push_back({w[i], i});
}
std::sort(local_w.begin(), local_w.end());
std::deque<int> ans;
int p = 0, k = -1, sum = 0;
while (k < n) {
if (l <= sum && sum <= u) {
// conv ans to vector;
std::vector<int32_t> rans;
for (const auto& a : ans) {
rans.push_back(a);
}
std::sort(rans.begin(), rans.end());
return rans;
} else if ((k < p) || (sum < l)) {
k++;
if (k >= n) break;
ans.push_back(local_w[k][1]);
sum += local_w[k][0];
} else if (sum > u) {
// remove first element.
ans.pop_front();
sum -= local_w[p][0];
p++;
}
}
return std::vector<int32_t>(0);
}
#ifdef GARY_DBG
void solve() {
int n;
std::cin >> n;
std::vector<int> w(n);
for (auto& a : w) {
std::cin >> a;
}
int l, u;
std::cin >> l >> u;
const auto res = find_subset(l, u, w);
if (res.size() == 0) {
std::cout << "RETURNED EMPTY VECTOR (...)\n";
return;
}
std::cout << "res ~> ";
for (const auto& a : res) {
std::cout << a << " ";
}
std::cout << '\n';
// check if condition met:
int sum = 0;
for (const auto& a : res) {
sum += w[a];
}
if (l <= sum && sum <= u) {
std::cout << "YES: SOLUTION CORRECT\n";
} else {
std::cout << "l: " << l << " | u: " << u << " " << " | got: " << sum << '\n';
}
std::cout << l << " <= " << sum << " <= " << u << '\n';
}
int32_t main() {
std::ios_base::sync_with_stdio(0);
std::cin.tie(0);
std::cout.tie(0);
int t = 1;
// std::cin >> t;
for (; t > 0; t--) {
solve();
}
return 0;
}
#endif
# | 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... |