blob: bccad43f27837d0ad7d5ce8e33776cc5378480db (
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
|
#! /usr/bin/python3
import unittest
def cc(list):
n=sorted(range(len(list)), key=lambda x: list[x])
k=[0] * len(list)
for i in n:
nr=[1]
if (i > 0 and list[i-1] < list[i]):
nr.append(k[i-1]+1)
if (i < len(list)-1 and list[i+1] < list[i]):
nr.append(k[i+1]+1)
k[i]=max(nr)
return sum(k)
class TestCc(unittest.TestCase):
def test_ex1(self):
self.assertEqual(cc((1,2,2)),4,'example 1')
def test_ex2(self):
self.assertEqual(cc((1,4,3,2)),7,'example 2')
unittest.main()
|