Language: C++


#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e20);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a>b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a<b ? : a = b; }

class subsequence 
{
private:
    int Left, Right;
    long long S;
    int N;
    long long LRsum;
    std::vector<long long> sequence;
public:
    virtual void move_left_pointer();
    virtual void move_right_pointer();
    virtual bool is_cond();
    virtual bool is_right_end();
    virtual std::pair<int, int> no_next();
    virtual std::pair<int, int> get_LR();


    void set_S(long long S);
    subsequence(std::vector<long long>& sequence, int N, int start);
};

subsequence::subsequence(std::vector<long long>& sequence, int N, int start) :
    sequence(sequence),
    N(N),
    Left(start),
    Right(start),
    S(0),
    LRsum(0)
{
}

void subsequence::set_S(long long S) {
    this->S = S;
}

void subsequence::move_left_pointer() {
    LRsum -= sequence[Left];
    Left++;
}

void subsequence::move_right_pointer() {
    if (Right < N) {
        LRsum += sequence[Right];
        Right++;
    }
}

bool subsequence::is_cond() {
    if (LRsum >= S)
        return true;
    return false;
}

bool subsequence::is_right_end() {
    if (Right >= N)
        return true;
    return false;
}

std::pair<int, int> subsequence::no_next() {
    return std::make_pair(-1, -1);
}

std::pair<int, int> subsequence::get_LR() {
    return std::make_pair(Left, Right);
}

int main() {

    std::vector<long long> sequence;
    int N, K;
    std::cin >> N >> K;
    for (int i = 0; i < N; i++) {
        long long a;
        std::cin >> a;
        sequence.push_back(a);
    }
    std::sort(sequence.begin(), sequence.end());

    subsequence seq(sequence, sequence.size(), 0);
    seq.set_S(K);
    int min_len = INT_MAX;
    int count = 0;
    int left_pointer_move_count = 0;
    while (1) {
        bool is_break = false;
        while (seq.is_cond() == false && seq.is_right_end() == false) {
            if (left_pointer_move_count > 0) {
                count += (left_pointer_move_count - 1);
                is_break = true;
            }
            left_pointer_move_count = 0;
            seq.move_right_pointer();
        }
        if (is_break == true)
            break;
        if (seq.is_cond() == false) {
            if (left_pointer_move_count > 0)
                count += (left_pointer_move_count - 1);
            break;
        }
        seq.move_left_pointer();
        left_pointer_move_count++;
    }
    
    std::cout << count << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:129:19: error: 'INT_MAX' was not declared in this scope
  129 |     int min_len = INT_MAX;
      |                   ^~~~~~~
a.cc:30:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   29 | #include <functional>
  +++ |+#include <climits>
   30 | using namespace std;