# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
112321 | 2019-05-18T18:22:42 Z | ioilolcom | Detecting Molecules (IOI16_molecules) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define x first #define y second typedef long long int ll; int main() { ios_base:: sync_with_stdio(false); cin.tie(0); int n; cin>>n; int l,u; vector<int> w; w.resize(n); for(int i=0; i<n; i++) { cin>>w[i]; } cin>>l>>u; sort(w.begin(),w.end()); //vector<int> ans; //int n=(int)w.size(); vector<pair<int,int> > ww; for(int i=0; i<(int)w.size(); i++) { ww.push_back({w[i],i}); } sort(ww.begin(),ww.end()); vector<int> ans; int a=0; int r=0; ll sum=0; for(int i=0; i<n; i++) { if(sum+ww[i].x<=l) {sum+=ww[i].x; r=i;} else{ break; } } while(r<n) { if(sum>=l&&sum<=u) { break; } sum+=ww[++r].x; sum-=ww[a++].x; } for(int i=a; i<=r; i++) { ans.push_back(i); } for(int aa:ans) { cout<<aa<<" "; } cout<<endl; return 0; }