#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
using u32 = unsigned;
using u64 = unsigned long long;
#define fi first
#define se second
template<class A, class B> inline bool maximize(A& x, B y) {
if (x < y) {
x = y;
return true;
} else
return false;
};
template<class A, class B> inline bool minimize(A& x, B y) {
if (x > y) {
x = y;
return true;
} else
return false;
};
vector<int> find_subset(int l, int r, vector<int> a) {
vector<pair<int, int>> p;
for (int i = 0; i < a.size(); i++)
p.push_back(make_pair(a[i], i + 1));
sort(p.begin(), p.end());
int sum = 0, j = 0;
for (int i = 0; i < (int)a.size(); i++) {
sum += p[i].fi;
while (sum > r)
sum -= p[j++].fi;
if (sum >= l) {
vector<int> ans;
for (int k = j; k <= i; k++)
ans.push_back(p[k].se);
sort(ans.begin(), ans.end());
return ans;
}
}
return {};
}
void komasan() {
vector<int> ans = find_subset(15, 17, {6, 8, 8, 7});
for (int x : ans)
cout << x << ' ';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen(".inp", "r", stdin);
// freopen(".out", "w", stdout);
komasan();
}
Compilation message
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:30:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for (int i = 0; i < a.size(); i++)
| ~~^~~~~~~~~~
/usr/bin/ld: /tmp/ccGPduWb.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccsCFGNb.o:molecules.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status