Advertisement
Mishakis

mock2_2

Oct 15th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1.  
  2.  
  3.  
  4. import java.util.Scanner;
  5.  
  6.  
  7. public class Main {
  8.  
  9.  
  10.  
  11.     public static void main(String[] args) {
  12.         Scanner scanner = new Scanner(System.in);
  13.  
  14.        int n = scanner.nextInt();
  15.        
  16.  
  17.        int groupSpeed = scanner.nextInt();
  18.         int bestLength = 1;
  19.         int bestSum = groupSpeed;
  20.        int groupLength = 1;
  21.        int groupSum = groupSpeed;
  22.  
  23.        for(int i = 0; i < n - 1; i++){
  24.            int speed = scanner.nextInt();
  25.  
  26.            if(groupSpeed < speed){
  27.                groupLength++;
  28.                groupSum += speed;
  29.  
  30.            }else{
  31.  
  32.                groupSpeed = speed;
  33.                groupSum = speed;
  34.                groupLength = 1;
  35.            }
  36.            if(bestLength < groupLength){
  37.                bestLength = groupLength;
  38.                bestSum = groupSum;
  39.            }else if(bestLength == groupLength){
  40.                bestSum = Math.max(bestSum, groupSum);
  41.            }
  42.        }
  43.         System.out.println(bestSum);
  44.     }
  45.  
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement