Submission #6568973


Source Code Expand

Copy
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

int A[100009], B[100009];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N; cin >> N;
	for (int i = 0; i <= N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) cin >> B[i];

	ll ans = 0;

	for (int i = 0; i < N; i++) {
		if (A[i] >= B[i]) {
			// できるだけ倒す
			ans += B[i];
			A[i] -= B[i];
			B[i] = 0;
		}
		else {
			// 全部倒す
			ans += A[i];
			B[i] -= A[i];
			A[i] = 0;

			// 次の街もできるだけ倒す
			if (A[i + 1] >= B[i]) {
				ans += B[i];
				A[i + 1] -= B[i];
				B[i] = 0;
			}
			else { // 全部倒せた
				ans += A[i + 1];
				B[i] -= A[i + 1];
				A[i + 1] = 0;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Submission Info

Submission Time
Task C - City Savers
User lapis_Lazuri
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1121 Byte
Status AC
Exec Time 22 ms
Memory 1024 KB

Judge Result

Set Name All Sample
Score / Max Score 300 / 300 0 / 0
Status
AC × 17
AC × 3
Set Name Test Cases
All sample_01, sample_02, sample_03, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14
Sample sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
sample_01 AC 1 ms 256 KB
sample_02 AC 1 ms 256 KB
sample_03 AC 1 ms 256 KB
testcase_01 AC 13 ms 768 KB
testcase_02 AC 12 ms 640 KB
testcase_03 AC 21 ms 1024 KB
testcase_04 AC 21 ms 1024 KB
testcase_05 AC 6 ms 512 KB
testcase_06 AC 12 ms 768 KB
testcase_07 AC 19 ms 1024 KB
testcase_08 AC 21 ms 1024 KB
testcase_09 AC 17 ms 896 KB
testcase_10 AC 21 ms 1024 KB
testcase_11 AC 18 ms 896 KB
testcase_12 AC 1 ms 256 KB
testcase_13 AC 22 ms 1024 KB
testcase_14 AC 1 ms 256 KB