File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+ static BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
7+ static BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System . out));
8+ static StringTokenizer st;
9+ static int N ;
10+ static int [] buildings;
11+ static int [] cnt;
12+ static int max;
13+
14+ public static void main (String [] args ) throws IOException {
15+ N = Integer . parseInt(br. readLine());
16+ buildings = new int [N + 1 ];
17+ cnt = new int [N + 1 ];
18+
19+ st = new StringTokenizer (br. readLine());
20+ for (int i = 1 ; i <= N ; i++ ) {
21+ buildings[i] = Integer . parseInt(st. nextToken());
22+ }
23+
24+ for (int i = 1 ; i < N ; i++ ) {
25+ for (int j = i+ 1 ; j <= N ; j++ ) {
26+ double slope = (double )(buildings[j]- buildings[i]) / (j- i);
27+ boolean isPossible = true ;
28+ for (int k = 1 ; i+ k < j; k++ ) {
29+ if (buildings[i]+ (slope* k) <= buildings[i+ k]){
30+ isPossible = false ;
31+ break ;
32+ }
33+ }
34+ if (isPossible){
35+ cnt[i]++ ;
36+ cnt[j]++ ;
37+ }
38+ }
39+ }
40+ for (int i = 1 ; i <= N ; i++ ) {
41+ max = Math . max(cnt[i], max);
42+ }
43+ bw. write(max+ " " );
44+ bw. close();
45+ }
46+ }
47+ ```
You can’t perform that action at this time.
0 commit comments