結果
| 問題 | No.2566 美しい整数列 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-12-02 15:52:47 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 893 ms / 2,000 ms | 
| コード長 | 1,113 bytes | 
| コンパイル時間 | 3,592 ms | 
| コンパイル使用メモリ | 89,044 KB | 
| 実行使用メモリ | 84,328 KB | 
| 最終ジャッジ日時 | 2024-09-26 19:27:37 | 
| 合計ジャッジ時間 | 20,219 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 21 | 
ソースコード
import java.util.*;
import java.io.*;
class Main{
	private static final BufferedReader br =
		new BufferedReader(new InputStreamReader(System.in));
	private static final PrintWriter out =
		new PrintWriter(System.out);
	public static void main(String[] args)throws IOException{
		String[] str = br.readLine().split(" ");
		int N = Integer.parseInt(str[0]);
		int M = Integer.parseInt(str[1]);
		str = br.readLine().split(" ");
		int[] A = new int[N];
		for(int i=0;i<N;i++)
			A[i] = Integer.parseInt(str[i]);
		str = br.readLine().split(" ");
		int[] B = new int[M];
		for(int i=0;i<M;i++)
			B[i] = Integer.parseInt(str[i]);
		str = br.readLine().split(" ");
		int[] C = new int[N];
		for(int i=0;i<N;i++)
			C[i] = Integer.parseInt(str[i]);
		HashMap<Long,Long> map = new HashMap<>();
		long now = A[0];
		map.put(0L,(long)C[0]);
		for(int i=1;i<N;i++){
			now += B[(i-1)%M];
			map.merge(now-A[i],(long)C[i],Long::sum);
		}
		long sumC = 0;
		for(long num:C)
			sumC += num;
		long max = 0;
		for(long num:map.values())
			max = Math.max(num,max);
		out.println(sumC-max);
		br.close();
		out.close();
	}
}
            
            
            
        