Submission #309444

# Submission time Handle Problem Language Result Execution time Memory
309444 2020-10-03T14:00:01 Z cig32 Detecting Molecules (IOI16_molecules) C++14
Compilation error
0 ms 0 KB
#include<molecules.h>
#define ll long long
using namespace std;
int main(){
	ll n,l,u;
    cin >> n >> l>>u;
    pair<ll,ll> w[n];
    bool used[n];
    ll tot_sum=0;
    for(int i=0;i<n;i++)cin>>w[i].first;
    for(int i=0;i<n;i++)w[i].second=i;
    for(int i=0;i<n;i++)tot_sum+=w[i].first;
    for(int i=0;i<n;i++)used[i]=false;
    sort(w,w+n);
    ll curr_sum=0, pt=0, nani=0;
    for(int i=0;i<n;i++){
        curr_sum+=w[i].first;
        if(u<curr_sum){
            curr_sum-=w[i].first;
            pt=i;
            break;
        }
        used[i]=true;
        nani++;
        if(l<=curr_sum&&curr_sum<=u){
            cout<<nani<<"\n";
            for(int j=0;j<n;j++){
                if(used[j])cout<<w[j].second<<" ";
            }
            cout<<"\n";
            return;
        }
    }
    for(int i=0;i<min(n-pt,pt);i++){
        curr_sum-=w[i].first;
        used[i]=false;
        curr_sum+=w[n-i-1].first;
        used[n-i-1]=true;
        if(l<=curr_sum&&curr_sum<=u){
            break;
        }
    }
    if(l<=curr_sum&&curr_sum<=u){
        cout << nani << "\n";
        for(int i=0;i<n;i++){
            if(used[i]) cout<<w[i].second<<" ";
        }
    }
    else{
        cout<<"0\n";
    }
}

Compilation message

molecules.cpp: In function 'int main()':
molecules.cpp:6:5: error: 'cin' was not declared in this scope
    6 |     cin >> n >> l>>u;
      |     ^~~
molecules.cpp:2:1: note: 'std::cin' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
    1 | #include<molecules.h>
  +++ |+#include <iostream>
    2 | #define ll long long
molecules.cpp:14:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   14 |     sort(w,w+n);
      |     ^~~~
      |     short
molecules.cpp:26:13: error: 'cout' was not declared in this scope
   26 |             cout<<nani<<"\n";
      |             ^~~~
molecules.cpp:26:13: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
molecules.cpp:31:13: error: return-statement with no value, in function returning 'int' [-fpermissive]
   31 |             return;
      |             ^~~~~~
molecules.cpp:44:9: error: 'cout' was not declared in this scope
   44 |         cout << nani << "\n";
      |         ^~~~
molecules.cpp:44:9: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
molecules.cpp:50:9: error: 'cout' was not declared in this scope
   50 |         cout<<"0\n";
      |         ^~~~
molecules.cpp:50:9: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?