-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask10.cs
45 lines (40 loc) · 1.17 KB
/
Task10.cs
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
using System;
using CodEx;
namespace ConsoleApplication10
{
class Task10
{
static void Main(string[] args)
{
int K = Reader.Console().Int();
int[] s = new int[K];
int[] a = new int[K];
int[] b = new int[K];
int l;
for (int i = 0; i < K; i++)
s[i] = Reader.Console().Int();
for (int i = 0; i < K; i++)
{
l = 0;
for (int j = 0; j < i; j++)
if (s[i] >= s[j] && a[j] > l)
l = a[j];
a[i] = l + 1;
}
for (int i = K - 1; i >= 0; i--)
{
l = 0;
for (int j = K - 1; j >= i; j--)
if (s[i] <= s[j] && b[j] > l)
l = b[j];
b[i] = l + 1;
}
l = a[K - 1];
for (int i = 0; i < K - 1; i++)
for (int j = i + 1; j < K; j++)
if (a[i] + b[j] > l)
l = a[i] + b[j];
Console.WriteLine(l);
}
}
}