天天看點

codeforces A. Valera and Plates 題解

valera is a lazy student. he has m clean bowls and k clean

plates.

valera has made an eating plan for the next n days. as valera is lazy, he will eat exactly one dish per day. at that, in order to eat a dish,

he needs exactly one clean plate or bowl. we know that valera can cook only two types of dishes. he can eat dishes of the first type from bowls and dishes of the second type from either bowls

or plates.

when valera finishes eating, he leaves a dirty plate/bowl behind. his life philosophy doesn‘t let him eat from dirty kitchenware. so sometimes he needs to wash his plate/bowl before eating. find

the minimum number of times valera will need to wash a plate/bowl, if he acts optimally.

input

the first line of the input contains three integers n, m, k (1?≤?n,?m,?k?≤?1000) —

the number of the planned days, the number of clean bowls and the number of clean plates.

the second line contains n integers a1,?a2,?...,?an (1?≤?ai?≤?2).

if ai equals

one, then on day i valera will eat a first type dish. if ai equals

two, then on day i valera will eat a second type dish.

output

print a single integer — the minimum number of times valera will need to wash a plate/bowl.

sample test(s)

本題也是使用暴力法了。

最難的就是讀懂題目了。原來這個家夥這麼賴,一次隻洗一個碗,從不肯多洗。

有兩個思路:

1 模拟他洗碗的過程

2 計算多少碟菜,多少個碗和碟,然後進行加減處理

兩種方法都需要o(n)時間效率。

方法1:

方法二: