이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
vector<int> find_subset(int l, int r, vector<int> w){
vector<pair<int,int>> v;
int n=w.size();
for(int i=0; i<n; i++){
v.push_back({w[i], i});
}
sort(v.begin(), v.end());
long long sum=0;
vector<int> ans;
for(int i=0; i<n; i++){
sum+=v[i].first;
if(sum>=l){
if(sum<=r){
for(int j=0; j<=i; j++) ans.push_back(v[j].second);
return ans;
}
}
else{
int pos=0;
while(sum>r){
sum-=v[pos].first;
pos++;
}
if(sum>=l && sum<=r){
for(int j=pos; j<=i; j++) ans.push_back(v[j].second);
return ans;
}
}
}
return ans;
}
/*
int main(){
int n, l, r; cin>>n>>l>>r;
vector<int> w(n);
for(int i=0; i<n; i++){
cin>>w[i];
}
vector<int> ans=find_subset(l, r, w);
for(auto i:ans) cout<<i<<' ';
}
*/
/*
vector<int> find_subset(int l, int r, vector<int> w){
bool cek=true, beda=true;
for(int i=1; i<w.size(); i++){
if(w[i]!=w[i-1]) cek=false;
if(abs(w[i]-w[i-1])>=2) beda=false;
}
vector<int> ans;
if(cek){
int sum=0;
for(int i=0; i<w.size(); i++){
sum+=w[i];
ans.push_back(i);
if(sum>=l) break;
}
if(sum<l || sum>r) ans.clear();
}
return ans;
else if(beda){
int minx=1000, maxn=-1000;
for(int i=0; i<w.size(); i++){
minx=min(minx, w[i]);
maxn=max(maxn, w[i]);
}
vector<int> a, b;
for(int i=0; i<w.size(); i++){
if(w[i]==minx) a.push_back(i);
else b.push_back(i);
}
bool cek=false;
int sum=0;
vector<int> aa, bb;
for(int i=0; i<a.size(); i++){
sum+=minx;
aa.push_back(a[i]);
if(l-sum<=min(b.size(), aa.size())){
break;
}
if(sum>=l){
break;
}
}
if(sum>r) return ans;
if(sum>=l && sum<=r) return aa;
if(l-sum<=min(b.size(), aa.size())){
for(int i=0; i<aa.size(); i++) ans.push_back(aa[i]);
for(int i=0; i<l-sum; i++) ans.push_back(b[i]);
return ans;
}
for(int i=0; i<b.size(); i++){
sum+=maxn;
bb.push_back(b[i]);
}
}
}*/
# | 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... |