summaryrefslogtreecommitdiffstats
path: root/Main/C++/2015/S3.cpp
blob: 010a725bf7acf5bd0d8eccb1bacbe50ab53990a3 (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
39
40
41
42
43
44
45
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int G,P,counter=0,g;
    bool closed = false,can_land = false;
    cin >> G;
    cin >> P;
    bool docks[G] = {};
//    for (int i = 0; i < G; i++)
//    {
//        cout << docks[i] << ' ';
//    }
//    cout << endl;
    for (int i = 0; i < P;i++)
    {
        cin >> g;
        if (!closed)
        {
            can_land = false;
            for (int d = g; d > 0; d--)
            {
                if (docks[d-1] == false)
                {
                    docks[d-1] = true;
                    can_land = true;
                    break;
                }
            }
            if (!can_land)
            {
                closed = true;
            }
            else
            {
                counter++;
            }
        }
    }
    cout << counter;


    return 0;
}