回分類題庫
d297: (1052cp2_assignment1) Unfair Candy
出處:LeetCode

Difficulity : 1
Accepted : 84 Times | Submit :568 Times | Clicks : 1371
Accepted : 58 Users | Submit : 67 Users | Accepted rate : 87%
Time Limit :10000 ms | Memory Limit : 64000 KBytes
題目加入時間 : 2017-03-02 16:39

Content :

There are N children standing in a line. Each child is assigned a rating value.

You are giving candies to these children subjected to the following requirements:

What is the minimum candies you must give?

Input :

Each test case will start with a positive number, N (0 ≤ N ≤ 5000) followed by N positive integers (all are less than 100).

The first line is the number of children.

The second line is the rating value of each children and the rating value could be repeated. 

Output :

For each case print the minimum total number of candys in a single line.

Sample Input :

5
3 2 1 4 3
13
1 2 3 4 5 1 3 4 2 3 2 1 4
9
1 1 1 1 2 2 2 1 1

Sample Output :

9
30
12

Hint :


  

Author :

LeetCode (管理員:cp2ta)

  Solve it!   Status Forum (2)

C++
C
JAVA
79825. stanley (6 ms , 220KB)
79179. Morris1028 (7 ms , 334KB)
80000. nccucs105703030 (8 ms , 224KB)
79826. stanley (8 ms , 222KB)
79298. nccucs105703029 (8 ms , 226KB)
79699. nccucs104703019 (4 ms , 271KB)
78755. cp2ta (4 ms , 234KB)
80276. nccucs103703023 (5 ms , 228KB)
80133. nccucs105703028 (5 ms , 278KB)
80011. nccucs105703050 (5 ms , 244KB)
89348. nwgs524513cja (116 ms , 327KB)

執行時間會受很多因素影響因此僅供參考,主機等級請看這裡