100 分 但是还有两个测试样例过不了
查看原帖
100 分 但是还有两个测试样例过不了
981981
little_whitezzz楼主2023/12/15 10:54
import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {
	static int N = 100010;
	static long[] a = new long[N];
	static long n,x;
	public static void main(String[] args) {
		Scanner sc = new Scanner(new BufferedInputStream(System.in));
		n = sc.nextLong();
		x = sc.nextLong();
		long ans = 0;
		a[0] = sc.nextLong();
		for(int i = 1;i < n;i ++) {
			a[i] = sc.nextLong();
			if(a[i] + a[i - 1] > x) {
				ans += a[i] + a[i - 1] - x;
				a[i] = a[i] - (a[i] + a[i - 1] - x);
			}
		}
		System.out.println(ans);
	}

}
2023/12/15 10:54
加载中...