Submission #823872

#TimeUsernameProblemLanguageResultExecution timeMemory
823872rainboyTriangle Collection (CCO23_day2problem3)C11
10 / 25
54 ms564 KiB
#include <stdio.h>
#include <string.h>

#define N	2000

int main() {
	static int aa[N], aa_[N];
	int n, q, i, j, d;
	long long k, ans;

	scanf("%d%d", &n, &q);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	while (q--) {
		scanf("%d%d", &i, &d), i--;
		aa[i] += d;
		memcpy(aa_, aa, n * sizeof *aa);
		ans = 0;
		for (i = n - 1, j = n - 1; i >= 0; i--)
			while (aa_[i] >= 2) {
				while (j >= 0 && (j > i * 2 || aa_[j] % 2 == 0))
					j--;
				if (j >= 0)
					ans++, aa_[i] -= 2, aa_[j]--;
				else {
					k = 0;
					while (i >= 0)
						k += aa_[i], i--;
					ans += k / 3;
					break;
				}
			}
		printf("%lld\n", ans);
	}
	return 0;
}

Compilation message (stderr)

Main.c: In function 'main':
Main.c:11:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  scanf("%d%d", &n, &q);
      |  ^~~~~~~~~~~~~~~~~~~~~
Main.c:13:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
Main.c:15:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   scanf("%d%d", &i, &d), i--;
      |   ^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...