2051A - A. Preparing for the Olympiad

 
public class App {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String[] arr1 = new String[n];
        String[] arr2 = new String[n];
        for (int i = 0; i < n; ++i) {
            sc.nextLine();
            arr1[i] = sc.nextLine();
            arr2[i] = sc.nextLine();
        }
        for (int i = 0; i < n; ++i) {
            String[] temp = arr1[i].split(" ");
            int[] src1 = new int[temp.length];
            for (int j = 0; j < src1.length; ++j) {
                src1[j] = Integer.parseInt(temp[j]);
            }
 
            temp = arr2[i].split(" ");
            int[] src2 = new int[temp.length];
            for (int j = 0; j < src2.length; ++j) {
                src2[j] = Integer.parseInt(temp[j]);
            }
 
            int cnt = src1[src1.length - 1];
            for (int j = 0; j < src1.length - 1; ++j) {
                if (src1[j] > src2[j + 1]) cnt += src1[j] - src2[j + 1];
            }
            System.out.println(cnt);
        }
        sc.close();
    }
}
posted @ 2025-04-03 09:44  kayaker  阅读(37)  评论(0)    收藏  举报