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>
#include <ext/pb_ds/assoc_container.hpp>
#include "molecules.h"
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define END '\n'
#define inf 9e18
#define ff first
#define ss second
#define pb push_back
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
int n = w.size();
vector<pair<ll, int>> A(n);
for (int i = 0; i < n; ++i) A[i] = {w[i], i};
sort(all(A));
auto it = lower_bound(all(A), pair<ll, int>(l, 0));
vi ans;
if (it != A.end() && it->ff >= l && it->ff <= u) {
ans.pb(it->ss);
return ans;
}
int lo = 0, hi;
if (it == A.end() || it->ff > u) hi = (it - A.begin());
// cout << hi << END;
ll sum = 0;
set<int> s;
for (int i = 0; i < hi; ++i) {
sum += A[i].ff;
s.insert(A[i].ss);
if (sum >= l && sum <= u) {
for (auto u: s) ans.pb(u);
return ans;
}
if (sum > u) {
for (int j = 0; j < i; ++j) {
ll nsum = sum - A[j].ff;
if (nsum >= l && nsum <= u) {
s.erase(A[j].ss);
for (auto u: s) ans.pb(u);
return ans;
}
}
}
}
return ans;
}
// void solve(){
// }
// int main()
// {
// ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
// int t = 1;
// cin >> t;
// while(t--){
// solve();
// }
// return 0;
// }
Compilation message (stderr)
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:42:9: warning: unused variable 'lo' [-Wunused-variable]
42 | int lo = 0, hi;
| ^~
molecules.cpp:47:23: warning: 'hi' may be used uninitialized in this function [-Wmaybe-uninitialized]
47 | for (int i = 0; i < hi; ++i) {
| ~~^~~~
# | 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... |