Could anybody tell me what's wrong with it ?
Thanks !
Here is my code:
Code: Select all
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
int main(){
int init_data;
int cnt=0;
while(cin>>init_data && init_data!=-1){
if(cnt) cout<<endl;
cnt++;
vector<int> h,m;
h.push_back(init_data);
m.push_back(1);
int data;
while(cin>>data && data!=-1){
int max=0;
for(int i=h.size()-1;i>=0;i--){
if(h[i]>=data){
if(m[i]>max) max=m[i];
}
}
m.push_back(max+1);
h.push_back(data);
}
cout<<"Test #"<<cnt<<':'<<endl
<<" maximum possible interception: "
<<*max_element(m.begin(),m.end())<<endl;
}
}
Input:
Code: Select all
25
5
4
3
2
1
0
24
23
22
21
3
2
1
24
24
24
24
24
-1
233
233
233
-1
0
-1
500
-1
423
312
23
234
234
22
2
32
-1
423
234
2434
525
23
4343
234
22
312
2
32
-1
3
432
423
2423
423
423
-1
3
7324
2352
23
432
432
432
32
324
23
2
22
2
2
-1
389
207
155
300
299
170
158
65
-1
23
34
21
-1
32767
32764
32760
32000
1
-1
-1
Code: Select all
Test #1:
maximum possible interception: 8
Test #2:
maximum possible interception: 3
Test #3:
maximum possible interception: 1
Test #4:
maximum possible interception: 1
Test #5:
maximum possible interception: 6
Test #6:
maximum possible interception: 5
Test #7:
maximum possible interception: 4
Test #8:
maximum possible interception: 10
Test #9:
maximum possible interception: 6
Test #10:
maximum possible interception: 2
Test #11:
maximum possible interception: 5