CSES - Datatähti 2021 alku - Results
Submission details
Task:Alitaulukot
Sender:tassu
Submission time:2020-09-28 10:15:44 +0300
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:27:25: error: 'INT_MAX' was not declared in this scope
             int small = INT_MAX; // iso luku
                         ^~~~~~~
input/code.cpp:27:25: note: suggested alternative: 'INT8_MAX'
             int small = INT_MAX; // iso luku
                         ^~~~~~~
                         INT8_MAX

Code

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <limits>

using namespace std;

int main() {
    // ios_base::sync_with_stdio(0);
    // cin.tie(0);

    int n, k;
    cin >> n >> k;

    int result = 0;

    vector<int> table;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        table.push_back(x);
    }

    for (int a = 0; a < n; a++) {
        for (int b = a; b < n; b++) {
            int small = INT_MAX; // iso luku
            int large = 0;
            for (int c = a; c <= b; c++) {
                small = min(small, table[c]);
                large = max(large, table[c]);
            }

            if (large - small <= k) {
                result += 1;
            }
        }
    }

    cout << result << "\n";
}