CSES - Aalto Competitive Programming 2024 - wk3 - Wed - Results
Submission details
Task:Sorting coins
Sender:aalto2024c_009
Submission time:2024-09-18 17:49:50 +0300
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:7:5: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
    7 |     cin >> n >> m;
      |     ^~~
      |     std::cin
In file included from input/code.cpp:1:
/usr/include/c++/11/iostream:60:18: note: 'std::cin' declared here
   60 |   extern istream cin;           /// Linked to standard input
      |                  ^~~
input/code.cpp:9:5: error: 'vector' was not declared in this scope; did you mean 'std::vector'?
    9 |     vector<int> r_coins;
      |     ^~~~~~
      |     std::vector
In file included from /usr/include/c++/11/vector:67,
                 from input/code.cpp:2:
/usr/include/c++/11/bits/stl_vector.h:389:11: note: 'std::vector' declared here
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
input/code.cpp:9:12: error: expected primary-expression before 'int'
    9 |     vector<int> r_coins;
      |            ^~~
input/code.cpp:10:12: error: expected pri...

Code

#include <iostream>
#include <vector>
 
int main() {
    
    int n, m; // coins, holes
    cin >> n >> m;
 
    vector<int> r_coins;
    vector<int> r_holes;
    
 
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        r_coins.push_back(a);
    }
    
    for (int i = 0; i < m; i++) {
        int b;
        cin >> b;
        r_holes.push_back(b);
    }

    for(int i=0; i<n; i++ ){
        int a = r_coins[i];
        bool a=false;
        for(int l=0; l<m; l++){
            if(r_holes[l]>=r_coins[i]){
                cout<<l<<" ";
                a=true;
                break;
            }
        }
        if(a==false){
            cout << m+1 <<" ";
        }

    }
 
 
}