Submission #102021


Source Code Expand

import java.io.IOException;

public class Main {

	static int N,M;
	public static void main(String[] args) {
		N=nextInt();
		M=nextInt();
		int[] a = new int[N];
		long[] sum2 = new long[N+1]
				;

		long sum=0;
		for(int i=0;i<N;i++){
			a[i]=nextInt();
			if(i<N/2)sum+=a[i];
		}
		int left=0,right=N/2;
		for(int i=0;i<N;i++){
			sum2[i]=sum;
			left = (N+left-1)%N;
			right= (N+right-1)%N;
			
			sum = sum - a[right] + a[left];
			
		}
		for(int i=0;i<N;i++){
//			System.out.println(sum2[i]);
		}
		int now=0;
		long max=sum2[0];
		for(int i=0;i<M;i++){
			int s = nextInt();
			now = (now - (s-1)+N)%N;
			
//			System.out.println(now);
			if(max < sum2[now]){
				max = sum2[now];
			}
		}
		System.out.println(max);

	}
	static int nextInt() {
		int c = 0;
		try {
			c = System.in.read();
			while(c != '-' && (c < '0' || c > '9')) c = System.in.read();
			if(c == '-')
				return -nextInt();
			int res = 0;
			while(c >= '0' && c <= '9') {
				res = res*10 + c-'0';
				c = System.in.read();
			}
			return res;
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
		return -1;
	}
}

Submission Info

Submission Time
Task J - Very Intellectual Card Game
User TowersofHanoi
Language Java (OpenJDK 1.7.0)
Score 100
Code Size 1216 Byte
Status AC
Exec Time 462 ms
Memory 24240 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 18
Set Name Test Cases
All 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 2, 3, 4, 5, 6, 7, 8, 9
Case Name Status Exec Time Memory
1 AC 368 ms 20528 KB
10 AC 370 ms 20660 KB
11 AC 369 ms 20656 KB
12 AC 376 ms 20524 KB
13 AC 427 ms 23668 KB
14 AC 429 ms 23040 KB
15 AC 446 ms 23808 KB
16 AC 459 ms 23936 KB
17 AC 456 ms 23808 KB
18 AC 462 ms 24240 KB
2 AC 368 ms 20528 KB
3 AC 367 ms 20532 KB
4 AC 376 ms 20656 KB
5 AC 367 ms 20532 KB
6 AC 378 ms 20448 KB
7 AC 383 ms 20660 KB
8 AC 369 ms 20536 KB
9 AC 367 ms 20536 KB