CSES - Aalto Competitive Programming 2024 - wk2 - Homework - Results
Submission details
Task:Apartments
Sender:arnxxau
Submission time:2024-09-09 16:08:30 +0300
Language:C++11
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:18:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   18 |     sort(size_applicant.begin(), size_applicant.end());
      |     ^~~~
      |     short

Code

#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n, m, k;
    cin >> n >> m >> k;

    //vector<vector<bool> > roads(c, vector<bool>(c, false));
    vector<int> size_applicant(n);
    vector<int> apartments(m);

    for (int i = 0; i < n; ++i) cin >> size_applicant[i];
    for (int i = 0; i < m; ++i) cin >> apartments[i];

    sort(size_applicant.begin(), size_applicant.end());

    sort(apartments.begin(), apartments.end());

    int ok = 0;
    int app = 0, apart = 0;
    while( app < n and apart < m) {
        
        int app_value = size_applicant[app];
        int apart_value = apartments[apart];
        //cout << app << "---" << apart << endl;
        //cout << app_value << "---" << apart_value << endl;

        
        if (apart_value - k > app_value) ++app;
        else if (app_value > apart_value + k) ++apart;
        else {
            ++ok; ++app; ++apart;
        }
    }

    cout << ok << endl;





}