codeforce 11 27 A C

A

Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day.

Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.

It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible.

Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.

Write a program that, given sequence ai, will print the minimum number of folders.

Input

The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.

Output

Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder.

If there are multiple ways to sort the reports into k days, print any of them.

Sample test(s)
Input
11 1 2 3 -4 -5 -6 5 -5 -6 -7 6
Output
3 5 3 3 
Input
5 0 -1 100 -1 0
Output
1 5 


水题啊~~一重循环就可以搞定啦、、


C

A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 to k.

On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival programme at least once. In other words, each integer from 1 to k occurs in the sequence a1, a2, ..., an at least once.

Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site.

As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress.

Valentine can't watch all n movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the k genres and will skip all the movies of this genre. He is sure to visit other movies.

Valentine wants to choose such genre x (1 ≤ x ≤ k), that the total number of after-movie stresses (after all movies of genre x are excluded) were minimum.

Input

The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 105), where n is the number of movies and k is the number of genres.

The second line of the input contains a sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ k), where ai is the genre of the i-th movie. It is guaranteed that each number from 1 to k occurs at least once in this sequence.

Output

Print a single number — the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number.

Sample test(s)
Input
10 3 1 1 2 3 2 3 3 1 1 3
Output
3
Input
7 3 3 1 3 2 3 1 2
Output
1
Note
 
 
C题还稍微有一定疑问,先放在这儿,有时间再来更
 
代码:
 
View Code
 1 #include<iostream>
 2 using namespace std;
 3 int a[105];
 4 int main(){
 5     int n;
 6     while(cin>>n){
 7           int times=0;
 8           int subtimes=0;
 9           int addtimes=0;
10           int temp;
11           for(int i=0;i<n;i++){
12                   cin>>temp;
13                   addtimes++;
14                   if(temp<0){
15                       subtimes++;
16                       if(subtimes>2){
17                            a[times++]=addtimes-1;
18                            addtimes=1;
19                            subtimes=1;
20                            }
21                            }
22                       if((i==(n-1))&&(addtimes!=0)){
23                            a[times++]=addtimes;
24                            }
25                            }
26           cout<<times<<endl;
27           for(int j=0;j<times;j++){
28                   cout<<a[j];
29                   if(j<times-1)
30                         cout<<" ";
31                         }
32          cout<<endl;
33          }
34        return 0;
35        } 

 

posted on 2012-11-27 15:08  yumao  阅读(318)  评论(0编辑  收藏  举报

导航