

Moderator: Board moderators
Code: Select all
8
1
-1
1
-100
1
-1
1
Of course not. If you want others to understand your test, you must write your tests in right form.Anyway my program were giving right answer.GVahe wrote:Did you realize that my test case was?Code: Select all
8 1 -1 1 -100 1 -1 1
Eduard wrote:Of course not. If you want others to understand your test, you must write your tests in right form.Anyway my program were giving right answer.GVahe wrote:Did you realize that my test case was?Code: Select all
8 1 -1 1 -100 1 -1 1
Eduard
I don't understand you.it means that I "help" u writing wrong test for which ur program was giving the right answer.
Code: Select all
1
8
1
-1
1
-100
1
-1
1
Code: Select all
The nicest part of route 1 is between stops 1 and 4
Code: Select all
20
6
1
0
0
0
1
6
1
0
0
1
-1
6
0
0
0
0
0
10
4
-5
4
-3
4
4
-4
4
-5
10
4
-5
4
-3
4
4
-4
4
5
6
-1
1
-1
1
-1
6
1
-1
1
-1
1
11
1
-1
1
-1
1
-1
1
-1
1
-1
12
1
-1
1
-1
1
-1
1
-1
1
-1
1
10
1
2
4
5
6
7
8
9
2
0
3
1
-1
6
1
1
-100
1
1
7
1
000
0
0
0
0
6
0
0
0
0
-10000
7
1
1
00
0
0
0
2
0
2
-100
13
1
1
1
1
-1
-1
-1
-1
1
1
1
1
6
1
2
3
4
-10
Code: Select all
The nicest part of route 1 is between stops 1 and 6
The nicest part of route 2 is between stops 1 and 5
Route 3 has no nice parts
The nicest part of route 4 is between stops 3 and 9
The nicest part of route 5 is between stops 3 and 10
The nicest part of route 6 is between stops 2 and 5
The nicest part of route 7 is between stops 1 and 6
The nicest part of route 8 is between stops 1 and 10
The nicest part of route 9 is between stops 1 and 12
The nicest part of route 10 is between stops 1 and 10
Route 11 has no nice parts
The nicest part of route 12 is between stops 1 and 2
The nicest part of route 13 is between stops 1 and 3
The nicest part of route 14 is between stops 1 and 7
Route 15 has no nice parts
The nicest part of route 16 is between stops 1 and 7
Route 17 has no nice parts
Route 18 has no nice parts
The nicest part of route 19 is between stops 1 and 13
The nicest part of route 20 is between stops 1 and 5
Code: Select all
#include <stdio.h>
int s[20003];
max_subsequence(int r,int t){
int i,j=0,max[20003],start[20003],res=1,st=-1,en=-1;
start[0]=1;
for(i=1;i<r;i++){
if(max[i-1]>=0){
max[i]+=max[i-1]+s[i];
start[i]=start[i-1];
}
else{
max[i]+=s[i];
start[i]=i;
}
}
for(i=r-1;i>0;i--){
if(max[i]>res){
res=max[i];
st=start[i];
en=i+1;
}
else if (max[i]==res){
if((i+1-start[i])>=(en-st)){
st=start[i];
en=i+1;
}
}
}
if(st==-1 && en==-1)
printf("Route %d has no nice parts\n",t+1);
else
printf("The nicest part of route %d is between stops %d and %d\n",t+1,st,en);
for(i=1;i<=r;i++)
max[i]=0;
}
int main(){
int t,r,i,j;
scanf("%d",&t);
for(i=0;i<t;i++){
scanf("%d",&r);
for(j=1;j<r;j++)
scanf("%d",&s[j]);
max_subsequence(r,i);
}
system("PAUSE");
return 0;
}
Code: Select all
9
6
1
0
0
0
1
6
1
0
0
1
-1
6
0
0
0
0
0
10
4
-5
4
-3
4
4
-4
4
-5
10
4
-5
4
-3
4
4
-4
4
5
6
-1
1
-1
1
-1
6
1
-1
1
-1
1
11
1
-1
1
-1
1
-1
1
-1
1
-1
12
1
-1
1
-1
1
-1
1
-1
1
-1
1
Code: Select all
The nicest part of route 1 is between stops 1 and 6
The nicest part of route 2 is between stops 1 and 5
Route 3 has no nice parts
The nicest part of route 4 is between stops 3 and 9
The nicest part of route 5 is between stops 3 and 10
The nicest part of route 6 is between stops 2 and 5
The nicest part of route 7 is between stops 1 and 6
The nicest part of route 8 is between stops 1 and 10
The nicest part of route 9 is between stops 1 and 12
Code: Select all
Route 1 has no nice parts
Route 2 has no nice parts
Route 3 has no nice parts
Route 4 has no nice parts
Route 5 has no nice parts
Route 6 has no nice parts
Route 7 has no nice parts
Route 8 has no nice parts
Route 9 has no nice parts
Code: Select all
1
10
20000
20000
20000
20000
20000
20000
20000
20000
20000
Code: Select all
The nicest part of route 1 is between stops 1 and 2