| Task: | Alitaulukot |
| Sender: | tassu |
| Submission time: | 2020-09-28 10:13:20 +0300 |
| Language: | C++ (C++11) |
| Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:25:25: error: 'INT_MAX' was not declared in this scope
int small = INT_MAX, large = 0;
^~~~~~~
input/code.cpp:25:25: note: suggested alternative: 'INT8_MAX'
int small = INT_MAX, large = 0;
^~~~~~~
INT8_MAX
input/code.cpp:28:17: error: 'large' was not declared in this scope
large = max(large, table[c]);
^~~~~
input/code.cpp:31:17: error: 'large' was not declared in this scope
if (large - small <= k) {
^~~~~Code
#include <iostream>
#include <vector>
#include <algorithm>
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, 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";
}
