Submission #2121230


Source Code Expand

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		int n=ir.nextInt();
		int k=ir.nextInt();
		long[] a=new long[n+2];
		for(int i=0;i<n;i++)
			a[i+1]=ir.nextLong();
		for(int i=0;i<=n;i++)
			a[i+1]+=a[i];
		long ret=0;
		for(int i=0;i<n-k+1;i++)
			ret+=a[i+k]-a[i];
		out.println(ret);
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}

Submission Info

Submission Time
Task C - 総和
User holeguma
Language Java8 (OpenJDK 1.8.0)
Score 100
Code Size 3357 Byte
Status AC
Exec Time 95 ms
Memory 22100 KB

Judge Result

Set Name sample subtask1 subtask2
Score / Max Score 0 / 0 50 / 50 50 / 50
Status
AC × 2
AC × 13
AC × 24
Set Name Test Cases
sample sample01.txt, sample02.txt
subtask1 00.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, sample01.txt, sample02.txt
subtask2 00.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, sample01.txt, sample02.txt, sample01.txt, sample02.txt
Case Name Status Exec Time Memory
00.txt AC 69 ms 20820 KB
01.txt AC 70 ms 21076 KB
02.txt AC 69 ms 19540 KB
03.txt AC 80 ms 18388 KB
04.txt AC 73 ms 19796 KB
05.txt AC 73 ms 21588 KB
06.txt AC 82 ms 18772 KB
07.txt AC 82 ms 19796 KB
08.txt AC 83 ms 21332 KB
09.txt AC 75 ms 21588 KB
10.txt AC 73 ms 18516 KB
11.txt AC 93 ms 20052 KB
12.txt AC 90 ms 19924 KB
13.txt AC 91 ms 18516 KB
14.txt AC 91 ms 16596 KB
15.txt AC 90 ms 21972 KB
16.txt AC 91 ms 22100 KB
17.txt AC 94 ms 21460 KB
18.txt AC 85 ms 18388 KB
19.txt AC 95 ms 18772 KB
sample01.txt AC 69 ms 19028 KB
sample02.txt AC 69 ms 19156 KB