이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> find_subset(int l, int u, vector<int> w) {
vector<pair<int,int>> arr;
int n = w.size(), temp = 0;
for (int i=0;i<n;i++) {
arr.push_back(make_pair(w[i],i));
}
sort(arr.begin(), arr.end());
vector<int> prefix(n);
for (int i=0;i<n;i++) {
temp += arr[i].first;
prefix[i] = temp;
}
vector<int> ansarr;
int bottom = 0, top = n-1, middle, base;
while (bottom + 1 < top) {
middle = (bottom + top)/2;
if (prefix[middle] <= l) {
bottom = middle;
} else if (prefix[middle] <= u) {
for (int i=0;i<middle+1;i++) {
ansarr.push_back(arr[i].second);
}
return ansarr;
} else {
top = middle;
}
}
if (prefix[top] <= l) {
base = top;
} else if (prefix[bottom] <= l) {
base = bottom;
} else {
return ansarr;
}
int anstotal = prefix[base], anstart = 0;
for (int i=0;i<n-base;i++) {
if (anstotal < l) {
if (i == n-base-1) {
return ansarr;
}
anstotal = prefix[i+base+1] - prefix[i];
} else {
anstart = i;
break;
}
}
int gap = anstart-1;
for (int i=0;i<base+1;i++) {
if (anstotal < u) {
for (int j=anstart-1;j<anstart+base+1;j++) {
if (j == gap) {
continue;
}
ansarr.push_back(arr[j].second);
}
break;
} else {
anstotal += arr[gap].first - arr[gap+1].first;
}
}
return ansarr;
}
# | 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... |