#include <bits/stdc++.h>
using namespace std;
vector < int > find_subset ( int left, int right, vector < int > y ){
long long n = y.size();
vector < long long > pref ( n + 5 ), suf ( n + 5 );
vector < pair < long long, long long >> a ( n + 5 );
for ( int i = 1; i <= n; i++ ) a[i].first = y[i - 1], a[i].second = i - 1;
sort ( a.begin() + 1, a.begin() + 1 + n );
for ( int i = 1; i <= n; i++ ) pref[i] = pref[i - 1] + a[i].first;
for ( int i = n; i >= 1; i-- ) suf[i] = suf[i + 1] + a[i].first;
vector < int > ans;
for ( int i = n + 1; i >= 1; i-- ){
int l = 1, r = i - 1, rec = 0;
while ( l <= r ){
int mid = ( l + r ) / 2;
if ( pref[mid] + suf[i] <= left ){
l = mid + 1;
rec = mid;
}
else r = mid - 1;
}
if ( pref[rec] + suf[i] >= left && pref[rec] + suf[i] <= right ){
for ( int j = 1; j <= rec; j++ ){
ans.push_back(a[j].second);
}
for ( int j = n; j >= i; j-- ){
ans.push_back(a[j].second);
}
sort ( ans.begin(), ans.end());
return ans;
}
if ( rec + 1 <= i - 1 ){
rec++;
if ( pref[rec] + suf[i] >= left && pref[rec] + suf[i] <= right ){
for ( int j = 1; j <= rec; j++ ){
ans.push_back(a[j].second);
}
for ( int j = n; j >= i; j-- ){
ans.push_back(a[j].second);
}
sort ( ans.begin(), ans.end());
return ans;
}
}
}
return ans;
}
signed main(){
vector < int > isi {15, 17, 16, 18};
vector < int > ans = find_subset ( 10, 20, isi );
for ( auto x : ans ) cout << x << " ";
}
Compilation message
/usr/bin/ld: /tmp/ccBlWqgk.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccS9Lt8j.o:molecules.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status