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 <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <set>
#include <iterator>
#include <stack>
#include <map>
#include <math.h>
#include <bitset>
#include <deque>
#include <string>
#include <tuple>
#include <queue>
#include <numeric>
#include <unordered_set>
#include <unordered_map>
#define pi 3.141592653589793238
#define ll long long
#define ld long double
#define rep(i, a, b) for (long long i = a; i <= b; i++)
#define mod 1000000007ll
#define INF 1000000000000000000
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define all(x) (x).begin (), (x).end ()
#define sz(x) (ll) (x).size ()
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())
#define rank rnk
#define log lg
#define fast \
ios_base::sync_with_stdio (false); \
cin.tie (NULL); \
cout.tie (NULL)
using namespace std;
std::vector<int> find_subset(int l, int u, std::vector<int> w)
{
int n=sz(w);
vector <pair<int,int>> arr(n);
rep(i,0,n-1)
arr[i]={w[i],i};
sort(all(arr));
int curr=0;
vector <int> idx;
bool done=false;
int lidx=-1;
rep(i,0,n-1)
{
curr+=arr[i].ff;
idx.pb(arr[i].ss);
lidx=i;
if(curr>=l && curr<=u)
{
done=true;
break;
}
else if(curr>u)
{
curr-=arr[i].ff;
idx.pop_back();
lidx--;
break;
}
}
if(done)
return idx;
// cout<<curr<<endl;
int fidx=0;
for(int i=n-1;i>=lidx+1;i--)
{
curr+=arr[i].ff-arr[fidx].ff;
idx.pb(arr[i].ss);
fidx++;
if(curr>=l && curr<=u)
break;
if(fidx==lidx+1)
break;
}
int s=sz(idx);
vector <int> ret;
rep(i,fidx,s-1)
ret.pb(idx[i]);
// cout<<curr<<endl;
if(curr>=l && curr<=u)
return ret;
else
return vector <int> ();
}
// signed main()
// {
// fast;
// freopen("milkorder.in","r",stdin);
// freopen("milkorder.out","w",stdout);
// auto v=find_subset(15,17, {6,8,8,7});
// for(auto x:v)
// cout<<x<<" ";
// return 0;
// }
# | 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... |