이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "molecules.h"
using namespace std;
#define ll long long
vector<int> find_subset(int l, int u, vector<int> w){
int n = w.size();
vector<pair<int,int>> W;
for(int i = 0; i < n; ++i){
W.push_back({w[i], i});
}
sort(W.begin(), W.end());
ll pref[n], suf[n];
for(int i = 0; i < n; ++i){
pref[i] = W[i].first;
if(i) pref[i] += pref[i - 1];
}
for(int i = n - 1; i >= 0; --i){
suf[i] = W[i].first;
if(i < n - 1) suf[i] += suf[i + 1];
}
if(pref[0] > u) return {};
if(suf[0] < l) return {};
if(pref[0] >= l) return {0};
int start = -1;
for(int i = 0; i < n; ++i){
if(pref[i] > l){
start = i - 1;
break;
}
}
int r = n - 1;
while(start >= 0){
int suf_pts = (r + 1 == n)? 0 : suf[r + 1];
int x = pref[start] + suf_pts;
if(x >= l && x <= u){
vector<int> ans;
for(int i = 0; i <= start; ++i)
ans.push_back(W[i].second);
for(int i = r + 1; i < n; ++i)
ans.push_back(W[i].second);
return ans;
}
start--;
r--;
}
int suf_pts = (r + 1 == n)? 0 : suf[r + 1];
if(suf_pts >= l && suf_pts <= u){
vector<int> ans;
for(int i = r + 1; i < n; ++i)
ans.push_back(W[i].second);
return ans;
}
return {};
}
// int32_t main(){
// auto ret = find_subset(15, 17, {6,8,8,7});
// for(auto x : ret) cout << x << " ";
// cout << "\n";
// ret = find_subset(14, 15, {5, 5, 6, 6});
// for(auto x : ret) cout << x << " ";
// cout << "\n";
// ret = find_subset(10, 20, {15, 17, 16, 18});
// for(auto x : ret) cout << x << " ";
// cout << "\n";
// }
# | 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... |