Submission #241403


Source Code Expand

Copy
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int[] t = new int[n];
		int max = 0;
		int maxIndex = 0;
		for (int i = 0; i < n; ++i) {
			t[i] = scan.nextInt();
			if (max < t[i]) {
				max = t[i];
				maxIndex = i;
			}
		}

		switch (n) {
			case 1 :
			case 2 :
				System.out.println(max);
				break;
			case 3 :
				int x = 0;
				for (int i = 0; i < n; i++) {
					if (i == maxIndex) {
						continue;
					}
					x += t[i];
				}
				
				System.out.println(Math.max(max, x));
				break;
			case 4:
				int y = 0;
				int min = Integer.MAX_VALUE;
				int minIndex = 0;
				for (int i = 0; i < n; i++) {
					if (i == maxIndex) {
						continue;
					}
					if (min > t[i]) {
						min = t[i];
						minIndex = i;
					}
					y += t[i];
				}
				if (y <= max) {
					System.out.println(max);
					break;
				}

				int y2 = 0;
				
				for (int i = 0; i < n; i++) {
					if (i == maxIndex || i == minIndex) {
						continue;
					}
					y2 += t[i];
				}
				
				System.out.println(Math.max(y2, max + min));
				break;
		}

		scan.close();

	}

}

Submission Info

Submission Time
Task A - 高橋君とお肉
User uriku
Language Java (OpenJDK 1.7.0)
Score 0
Code Size 1241 Byte
Status
Exec Time 446 ms
Memory 23284 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 subtask0-sample-01.txt, subtask0-sample-02.txt, subtask0-sample-03.txt
All 0 / 100 subtask0-sample-01.txt, subtask0-sample-02.txt, subtask0-sample-03.txt, subtask1-01.txt, subtask1-02.txt, subtask1-03.txt, subtask1-04.txt, subtask1-05.txt, subtask1-06.txt, subtask1-07.txt, subtask1-08.txt, subtask1-09.txt, subtask1-10.txt, subtask1-11.txt, subtask1-12.txt, subtask1-13.txt, subtask1-14.txt, subtask1-15.txt, subtask1-16.txt
Case Name Status Exec Time Memory
subtask0-sample-01.txt 430 ms 23128 KB
subtask0-sample-02.txt 418 ms 23140 KB
subtask0-sample-03.txt 410 ms 23092 KB
subtask1-01.txt 402 ms 23096 KB
subtask1-02.txt 413 ms 23164 KB
subtask1-03.txt 409 ms 23164 KB
subtask1-04.txt 417 ms 23172 KB
subtask1-05.txt 410 ms 23108 KB
subtask1-06.txt 403 ms 23144 KB
subtask1-07.txt 446 ms 23196 KB
subtask1-08.txt 406 ms 23152 KB
subtask1-09.txt 410 ms 23224 KB
subtask1-10.txt 413 ms 23260 KB
subtask1-11.txt 415 ms 23140 KB
subtask1-12.txt 420 ms 23156 KB
subtask1-13.txt 408 ms 23092 KB
subtask1-14.txt 401 ms 23284 KB
subtask1-15.txt 416 ms 23180 KB
subtask1-16.txt 405 ms 23164 KB