Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Main {
- private static ArrayList<Integer> sequence = new ArrayList<>();
- private static int sum;
- private static int length;
- public static void main(String[] args) throws IOException {
- Scanner sc = new Scanner(new File("C:\\Users\\adamk\\Desktop\\input.txt"));
- while (sc.hasNextInt()) {
- sequence.add(sc.nextInt());
- }
- for (int i = 0; i < sequence.size(); i++) {
- sequenceComparator(descending(i), i);
- sequenceComparator(ascending(i), i);
- }
- System.out.println(length + " " + sum);
- }
- private static int ascending(int j) {
- int ascLength = 1;
- for (int i = j; i < sequence.size() - 1; i++) {
- if (sequence.get(i) <= sequence.get(i + 1)) {
- ascLength++;
- } else
- break;
- }
- return ascLength;
- }
- private static int descending(int j) {
- int descLength = 1;
- for (int i = j; i < sequence.size() - 1; i++) {
- if (sequence.get(i) >= sequence.get(i + 1)) {
- descLength++;
- } else
- break;
- }
- return descLength;
- }
- private static void sequenceComparator(int length, int index) {
- if (Main.length < length) {
- Main.length = length;
- sum = 0;
- for (int j = index; j < Main.length + index; j++) {
- sum += sequence.get(j);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement