Submission #793866

# Submission time Handle Problem Language Result Execution time Memory
793866 2023-07-26T07:41:27 Z 박영우(#10061) Triangle Collection (CCO23_day2problem3) C++17
0 / 25
13 ms 364 KB
#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 202300
#define MAXS 500
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
int N, Q;
int arr[MAX];
int cpy[MAX];
int solve() {
	int i, j;
	for (i = 1; i <= N; i++) cpy[i] = arr[i];
	int cnt = 0;
	int ans = 0;
	for (i = 1; i <= N; i++) {
		if (arr[i] >= 2) {
			int m = min(arr[i] / 2, cnt);
			cnt -= m;
			ans += m;
			arr[i] -= m * 2;
		}
		if (arr[i] >= 3) {
			ans += arr[i] / 3;
			arr[i] %= 3;
		}
		if (arr[i] < 2) {
			cnt += arr[i];
			continue;
		}
		for (j = 1; j <= N; j++) {
			if (j >= i * 2) break;
			if (arr[j] >= 1) {
				arr[j]--;
				arr[i] = 0;
				ans++;
				break;
			}
		}
		cnt += arr[i];
	}
	for (i = 1; i <= N; i++) arr[i] = cpy[i];
	return ans;
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> N >> Q;
	int i;
	for (i = 1; i <= N; i++) cin >> arr[i];
	int a, b;
	while (Q--) {
		cin >> a >> b;
		arr[a] += b;
		cout << solve() << ln;
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -