summaryrefslogtreecommitdiff
path: root/I_anno/Programmazione_2/tastevin.cpp
blob: 301ebcfde53ac600aac829313e81a967809a1d8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
    ifstream in("input.txt");
    ofstream out("output.txt");

    for(int ts = 0; ts < 100; ++ts) {
        int N;
        in >> N;
        vector<int> arr(N);
        for(int i = 0; i < N; ++i) {
            in >> arr.at(i);
        }

        vector<int> paths(N, 1);

        for(int i = N-2; i >= 0; --i) {
            int mx = 0;
            for(int j = i+2; j < N; ++j) {
                if(mx < paths[j] && arr[j] >= arr[i]) {
                    mx = paths[j];
                }
            }
            paths[i] += mx;
        }

        out << *max_element(begin(paths), end(paths)) << '\n';
    }

    in.close();
    out.close();
    return 0;
}