結果

問題 No.2601 Very Poor
ユーザー ks2mks2m
提出日時 2024-01-12 22:22:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 782 ms / 2,000 ms
コード長 684 bytes
コンパイル時間 2,419 ms
コンパイル使用メモリ 75,756 KB
実行使用メモリ 73,128 KB
最終ジャッジ日時 2024-03-20 19:48:51
合計ジャッジ時間 22,286 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
57,964 KB
testcase_01 AC 132 ms
57,736 KB
testcase_02 AC 133 ms
57,600 KB
testcase_03 AC 134 ms
57,860 KB
testcase_04 AC 133 ms
57,988 KB
testcase_05 AC 208 ms
60,276 KB
testcase_06 AC 206 ms
60,244 KB
testcase_07 AC 205 ms
60,152 KB
testcase_08 AC 206 ms
60,248 KB
testcase_09 AC 204 ms
60,244 KB
testcase_10 AC 204 ms
60,228 KB
testcase_11 AC 209 ms
60,256 KB
testcase_12 AC 207 ms
60,280 KB
testcase_13 AC 208 ms
60,228 KB
testcase_14 AC 207 ms
60,212 KB
testcase_15 AC 771 ms
71,008 KB
testcase_16 AC 765 ms
70,480 KB
testcase_17 AC 782 ms
71,248 KB
testcase_18 AC 748 ms
71,824 KB
testcase_19 AC 730 ms
71,004 KB
testcase_20 AC 766 ms
70,864 KB
testcase_21 AC 742 ms
71,036 KB
testcase_22 AC 756 ms
70,584 KB
testcase_23 AC 751 ms
69,072 KB
testcase_24 AC 756 ms
70,964 KB
testcase_25 AC 747 ms
70,988 KB
testcase_26 AC 746 ms
71,268 KB
testcase_27 AC 772 ms
71,124 KB
testcase_28 AC 740 ms
73,128 KB
testcase_29 AC 756 ms
71,140 KB
testcase_30 AC 745 ms
70,908 KB
testcase_31 AC 759 ms
70,496 KB
testcase_32 AC 739 ms
70,956 KB
testcase_33 AC 753 ms
71,220 KB
testcase_34 AC 744 ms
71,312 KB
testcase_35 AC 205 ms
60,200 KB
testcase_36 AC 207 ms
60,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int n2 = n * 2;
		long[] a = new long[n2 + 1];
		for (int i = 1; i <= n; i++) {
			a[i] = sc.nextInt();
			a[i + n] = a[i];
		}
		sc.close();

		long ans = 0;
		long val = 0;
		int r = 0;
		for (int l = 0; l <= n; l++) {
			while (r < n2 && r - l < n - 1 && val <= x) {
				r++;
				val += a[r];
				if (val <= x) {
					ans = Math.max(ans, val);
				} else {
					break;
				}
			}
			val -= a[l];
			if (val <= x) {
				ans = Math.max(ans, val);
			}
		}
		System.out.println(ans);
	}
}
0