#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
typedef std::vector<int> VI;
constexpr auto MAX_N = 1000000;
class Przedzial
{
public:
Przedzial()
{
Lewo = Prawo = -1;
}
int Lewo;
int Prawo;
inline void DodajWartosc(int idx1)
{
if (idx1 < Lewo || Lewo<0) Lewo = idx1;
if (idx1 > Prawo || Prawo<0) Prawo = idx1;
}
inline int Dlugosc()
{
return Prawo - Lewo + 1;
}
};
int main()
{
int n;
auto _ = scanf("%d\n", &n);
VI oceny(n);
VI pozycje(n+1);
int maxCel = 1 + 2 * n;
for (int i = 0; i < n; i++)
{
auto _ = scanf("%d", &oceny[i]);
pozycje[oceny[i]] = i;
}
Przedzial p;
int ileWystapien = 0;
int curOcena = n;
while (p.Dlugosc() < n)
{
int nastepna = pozycje[curOcena--];
p.DodajWartosc(nastepna);
ileWystapien++;
}
printf("%d %d\n",maxCel, ileWystapien);
return 0;
}
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #define _CRT_SECURE_NO_WARNINGS #include <cstdio> #include <stdio.h> #include <iostream> #include <string.h> #include <math.h> #include <algorithm> #include <vector> typedef std::vector<int> VI; constexpr auto MAX_N = 1000000; class Przedzial { public: Przedzial() { Lewo = Prawo = -1; } int Lewo; int Prawo; inline void DodajWartosc(int idx1) { if (idx1 < Lewo || Lewo<0) Lewo = idx1; if (idx1 > Prawo || Prawo<0) Prawo = idx1; } inline int Dlugosc() { return Prawo - Lewo + 1; } }; int main() { int n; auto _ = scanf("%d\n", &n); VI oceny(n); VI pozycje(n+1); int maxCel = 1 + 2 * n; for (int i = 0; i < n; i++) { auto _ = scanf("%d", &oceny[i]); pozycje[oceny[i]] = i; } Przedzial p; int ileWystapien = 0; int curOcena = n; while (p.Dlugosc() < n) { int nastepna = pozycje[curOcena--]; p.DodajWartosc(nastepna); ileWystapien++; } printf("%d %d\n",maxCel, ileWystapien); return 0; } |
English