이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ccd ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
#define usaco freopen("(insert).in", "r", stdin);freopen("(insert).out", "w", stdout);
using namespace std;
/* ------------------------ hi lol ------------------------ */
// author : mzv
vector<int> find_subset(int l, int u, vector<int> w) { // array sucks at size (and also i keep getting CE when using int[], idk why :/)
int k = w.size();
vector<pair<int,int>>weight;
for (int i=0;i<k;i++) {
weight.push_back({w[i],i});
}
for (auto we : weight) {
cout << we.first << " " << we.second << endl;
}
sort(weight.begin(),weight.end());
int idx=0;
ll sum=0;
for (int i=0;i<k;i++) {
sum+=weight[i].first;
if (sum>u) {
while (sum>u) {
sum-=weight[idx].first;
idx++;
}
}
if (sum>=l&&sum<=u) {
// done
vector<int> v;
for (int x=idx;x<=i;x++) {
v.push_back(weight[x].second);
}
return v;
}
}
// not found
return {};
}
/*
int main() {
ccd
// usaco
// vector<int> p = find_subset(15, 17, {6, 8, 8, 7}); // 1 2
// vector<int> p = find_subset(14, 15, {5, 5, 6, 6}); // empty
// vector<int> p = find_subset(10, 20, {15, 17, 16, 18}); // 0
for (auto pp : p) {
cout << pp << " ";
}
}
*/
/*
two pointer approach
1 3 5 7 9
11 14
1
4
9
16
while --> 15,12 stop!
5,7 noted!
*/
# | 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... |