답안 #578773

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
578773 2022-06-17T23:04:52 Z AlperenT Homecoming (BOI18_homecoming) C++17
100 / 100
116 ms 16000 KB
#include <bits/stdc++.h>
#include "homecoming.h"

using namespace std;

const long long INF = 1e18;

long long solve(int n, int k, int *a, int *b){
	long long ans = 0;

	long long mx, cur, cost, nxtcost;

	for(int it = 1; it <= 2; it++){
		mx = (it == 1 ? -INF : 0);

		cost = accumulate(b, b + k, 0ll);

		cur = a[0] - cost;

		mx = max(mx, cur);

		for(int i = 1; i < n; i++){
			cost -= b[i - 1];

			if(i + k - 1 < n) nxtcost = b[i + k - 1];
			else if(it == 2) nxtcost = b[i + k - 1 - n];
			else nxtcost = 0;

			cur = max(a[i] + cur - nxtcost, a[i] - (cost + nxtcost) + mx);

			cost += nxtcost;

			mx = max(mx, cur);
		}

		ans = max(ans, mx);
	}

	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 4188 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 116 ms 15952 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 7 ms 1792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 32 ms 4188 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 116 ms 15952 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 7 ms 1792 KB Output is correct
16 Correct 103 ms 16000 KB Output is correct
17 Correct 47 ms 2304 KB Output is correct
18 Correct 91 ms 1488 KB Output is correct
19 Correct 94 ms 8232 KB Output is correct
20 Correct 77 ms 15900 KB Output is correct
21 Correct 64 ms 8260 KB Output is correct