#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
vi find_subset(int l,int r,vi w)
{
vector<pii>tab;
int n=sz(w);
tab.clear();
int licznik=1;
for (auto it:w)tab.pb(mp(it,licznik++));
sort(tab.begin(),tab.end());
int ile=0;
vi ans;
ans.clear();
int wskl=-1,wskr=-1;
vector<ll> pref;
pref.clear();
ll sum=0;
for (int i=0;i<n;i++)sum+=tab[i].st,pref.pb(sum);
for (int i=0;i<sz(pref);i++)
{
if (pref[i]>=l && pref[i]<=r)
{
wskl=0,wskr=i;
break;
}
else if (pref[i]>r)
{
int ile=pref[i]-r;
int wsk=*lower_bound(pref.begin(),pref.end(),ile);
if (pref[i]-wsk>=l && pref[i]-wsk<=r)
{
int wsk2=lower_bound(pref.begin(),pref.end(),ile)-pref.begin();
wskl=wsk2+1,wskr=i;
if (wskl>wskr)wskl=-1,wskr=-1;
else break;
}
}
}
if (wskl!=-1)for (int i=wskl;i<=wskr;i++)ans.pb(tab[i].nd);
return ans;
}
/*
int32_t main()
{
BOOST;
vi rak;
rak=find_subset(10, 20, {15, 17, 16, 18});
cout<<sz(rak)<<"\n";
for (auto it:rak)cout<<it<<" ";
return 0;
}
*/
Compilation message
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:25:6: warning: unused variable 'ile' [-Wunused-variable]
int ile=0;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 KB |
OK (n = 12, answer = YES) |
2 |
Correct |
4 ms |
256 KB |
OK (n = 12, answer = YES) |
3 |
Correct |
4 ms |
256 KB |
OK (n = 12, answer = NO) |
4 |
Correct |
5 ms |
384 KB |
OK (n = 12, answer = NO) |
5 |
Incorrect |
4 ms |
256 KB |
sum of weights should be in [290..300] but it is 301 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 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 |
- |