Submission #754689

#TimeUsernameProblemLanguageResultExecution timeMemory
754689alexander707070Detecting Molecules (IOI16_molecules)C++14
Compilation error
0 ms0 KiB
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute i

*/

#include <bits/stdc++.h>

using namespace std;

int n,pref[200007];
pair<int,int> a[200007];

vector<int> answer(int l,int r){
    vector<int> res;
    for(int i=l;i<=r;i++){
        res.push_back(a[i].second);
    }
    return res;
}


vector<int> find_subset(int l,int u,vector<int> w){
    n=w.size();
    for(int i=1;i<=n;i++){
        a[i]={w[i-1],i-1};
    }
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++){
        pref[i]=pref[i-1]+a[i].first;
    }
    for(int i=1;i<=n;i++){
        int ll=0,int rr=i;
        while(ll+1<rr){
            mid=(ll+rr)/2;
            if(pref[i]-pref[mid]>=l){
                ll=mid;
            }else{
                rr=mid;
            }
        }
        if(pref[i]-pref[ll-1]>=l and pref[i]-pref[ll-1]<=u){
            return answer(ll,i); 
        }
        }
    }
    
    return {};
}


Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:35:18: error: expected unqualified-id before 'int'
   35 |         int ll=0,int rr=i;
      |                  ^~~
molecules.cpp:36:20: error: 'rr' was not declared in this scope
   36 |         while(ll+1<rr){
      |                    ^~
molecules.cpp:37:13: error: 'mid' was not declared in this scope
   37 |             mid=(ll+rr)/2;
      |             ^~~
molecules.cpp: At global scope:
molecules.cpp:50:5: error: expected unqualified-id before 'return'
   50 |     return {};
      |     ^~~~~~
molecules.cpp:51:1: error: expected declaration before '}' token
   51 | }
      | ^
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:48:5: warning: control reaches end of non-void function [-Wreturn-type]
   48 |     }
      |     ^