CSES - Datatähti 2021 alku - Results
Submission details
Task:Alitaulukot
Sender:jusola
Submission time:2020-10-01 17:19:35 +0300
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp:3:10: fatal error: algorvalhm: No such file or directory
 #include <algorvalhm>
          ^~~~~~~~~~~~
compilation terminated.

Code

#include <iostream>
#include <vector>
#include <algorvalhm>

using namespace std;

unsigned int s(unsigned int n){
    return (n*(n+1))/2;
}


int main(){
    unsigned int n, k;
    unsigned int c = 0, r = 0;
    cin >> n >> k;

    unsigned int val = 0;
    cin >> val;
    unsigned int min = val;
    unsigned int max = val;
    for(unsigned int i = 0; i < n; i++){
        if(i > 0){
            cin >> val;
        }
        if(val > max){
            max = val;
            if(max - min > k){
                min = val;
                r += s(c);
                c = 0;
            }
        }
        if(val < min){
            min = val;
            if(max - min > k){
                max = val;
                r += s(c);
                c = 0;
            }
        }
        c++;
    }
    r += s(c);

    cout << r;

    return 0;
}