結果

問題 No.2601 Very Poor
ユーザー ks2mks2m
提出日時 2024-01-12 22:22:17
言語 Java
(openjdk 23)
結果
AC  
実行時間 874 ms / 2,000 ms
コード長 684 bytes
コンパイル時間 2,642 ms
コンパイル使用メモリ 80,504 KB
実行使用メモリ 66,412 KB
最終ジャッジ日時 2024-09-30 06:26:22
合計ジャッジ時間 24,201 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

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