# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
209865 | thebes | Detecting Molecules (IOI16_molecules) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MN = 2e5+5;
pair<int,int> arr[MN];
long long psa[MN];
int find_subset(int l,int u,int *w,int n,int *res){
int mn = w[0];
for(int i=0;i<n;i++)
mn = min(w[i], mn);
for(int i=0;i<n;i++)
arr[i]={w[i]-mn,i};
int ans = 0;
sort(arr,arr+n,[](pair<int,int>i,pair<int,int>j){return i.first<j.first;});
for(int i=0;i<n;i++) psa[i+1]=psa[i]+arr[i].first;
for(int i=1;i<=n;i++){
long long a=psa[i], b=psa[n]-psa[n-i];
if(a+1LL*i*mn<=1LL*u&&b+1LL*i*mn>=1LL*l){
ans = i;
for(int i=ans;i<=n;i++){
long long tmp = psa[i]-psa[i-ans]+1LL*mn*ans;
if(tmp>=l&&tmp<=u){
for(int j=i-ans;j<i;j++)
res[j-i+ans]=arr[j].second;
return ans;
}
}
}
}
return 0;
}