Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = scanner.nextInt();
- int groupSpeed = scanner.nextInt();
- int bestLength = 1;
- int bestSum = groupSpeed;
- int groupLength = 1;
- int groupSum = groupSpeed;
- for(int i = 0; i < n - 1; i++){
- int speed = scanner.nextInt();
- if(groupSpeed < speed){
- groupLength++;
- groupSum += speed;
- }else{
- groupSpeed = speed;
- groupSum = speed;
- groupLength = 1;
- }
- if(bestLength < groupLength){
- bestLength = groupLength;
- bestSum = groupSum;
- }else if(bestLength == groupLength){
- bestSum = Math.max(bestSum, groupSum);
- }
- }
- System.out.println(bestSum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement