| Task: | Alitaulukot |
| Sender: | AleksandrPolitov |
| Submission time: | 2020-10-04 12:53:23 +0300 |
| Language: | C++ (C++17) |
| Status: | COMPILE ERROR |
Compiler report
input/code.cpp:5:6: error: 'vector' in namespace 'std' does not name a template type
std::vector<int> nums;
^~~~~~
input/code.cpp: In function 'void step(int, int, int, int)':
input/code.cpp:10:16: error: 'nums' was not declared in this scope
int next = nums[num + c - 1];
^~~~
input/code.cpp:10:16: note: suggested alternative: 'num'
int next = nums[num + c - 1];
^~~~
num
input/code.cpp: In function 'int main()':
input/code.cpp:39:5: error: 'nums' was not declared in this scope
nums = new int[n];
^~~~
input/code.cpp:39:5: note: suggested alternative: 'puts'
nums = new int[n];
^~~~
puts
input/code.cpp:49:31: error: 'min' cannot be used as a function
min = min(min, nums[i])
^
input/code.cpp:48:31: warning: unused variable 'max' [-Wunused-variable]
int min = 1000000000, max = 1;
^~~Code
#include <iostream>
using namespace std;
std::vector<int> nums;
int n, k, res = 0;
void step(int c, int num, int min, int max) {
int next = nums[num + c - 1];
if (next > 0) {
/*for (int i = num; i < num + c - 1; i++)
{
cout << nums[i];
}
cout << next;
cout << endl;*/
if (next < min)
min = next;
if (next > max)
max = next;
//cout << min << " - " << max << endl;
//cout << c << ":" << num << ":" << min << ":" << max << ":" << next << endl;
if (max - min <= k) {
res++;
step(c + 1, num, min, max);
}
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
nums = new int[n];
for (int i = 0; i < n; i++)
cin >> nums[i];
res+=n;
for (int i = 0; i < n; i++)
{
int min = 1000000000, max = 1;
min = min(min, nums[i])
max = max(max, nums[i])
if (max - min <= k) {
step(2, i, min, max);
}
}
//step(1);
cout << res;
}