답안 #793778

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
793778 2023-07-26T06:41:26 Z 박상훈(#10058) Triangle Collection (CCO23_day2problem3) C++17
10 / 25
4000 ms 3408 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int n, q;
ll a[200200], b[200200];

int ok(ll cnt){
	for (int i=n;i;i--){
		b[i] = min(a[i] / 2, cnt);
		cnt -= b[i];
	}

	if (cnt > 0) return 0;

	ll need = 0, avail = 0;
	int pt = 0;

	for (int i=1;i<=n;i++){
		need += b[i];
		for (;pt<min(n, i*2-1);pt++){
			avail += a[pt+1] - b[pt+1] * 2;
		}

		if (need > avail) return 0;

		// if (cnt==4) printf(" need = %lld / avail = %lld / %lld %lld")
	}

	return 1;
}

ll naive(){
	ll l = 0, r = 1e14, ans = 0;
	while(l<=r){
		ll mid = (l+r)>>1;
		if (ok(mid)) ans = mid, l = mid+1;
		else r = mid-1;
	}

	return ans;
}

int main(){
	scanf("%d %d", &n, &q);
	for (int i=1;i<=n;i++) scanf("%lld", a+i);

	while(q--){
		int x, y;
		scanf("%d %d", &x, &y);
		a[x] += y;

		printf("%lld\n", naive());
	}
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |  scanf("%d %d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:47:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |  for (int i=1;i<=n;i++) scanf("%lld", a+i);
      |                         ~~~~~^~~~~~~~~~~~~
Main.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |   scanf("%d %d", &x, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 7 ms 316 KB Output is correct
4 Correct 7 ms 212 KB Output is correct
5 Correct 8 ms 212 KB Output is correct
6 Correct 287 ms 340 KB Output is correct
7 Correct 296 ms 340 KB Output is correct
8 Correct 136 ms 312 KB Output is correct
9 Correct 302 ms 340 KB Output is correct
10 Correct 277 ms 340 KB Output is correct
11 Correct 271 ms 340 KB Output is correct
12 Correct 265 ms 340 KB Output is correct
13 Correct 261 ms 340 KB Output is correct
14 Correct 127 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 7 ms 316 KB Output is correct
4 Correct 7 ms 212 KB Output is correct
5 Correct 8 ms 212 KB Output is correct
6 Correct 287 ms 340 KB Output is correct
7 Correct 296 ms 340 KB Output is correct
8 Correct 136 ms 312 KB Output is correct
9 Correct 302 ms 340 KB Output is correct
10 Correct 277 ms 340 KB Output is correct
11 Correct 271 ms 340 KB Output is correct
12 Correct 265 ms 340 KB Output is correct
13 Correct 261 ms 340 KB Output is correct
14 Correct 127 ms 308 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 486 ms 348 KB Output is correct
18 Correct 462 ms 348 KB Output is correct
19 Correct 482 ms 340 KB Output is correct
20 Correct 465 ms 348 KB Output is correct
21 Correct 313 ms 340 KB Output is correct
22 Correct 471 ms 352 KB Output is correct
23 Correct 374 ms 340 KB Output is correct
24 Correct 357 ms 340 KB Output is correct
25 Correct 463 ms 348 KB Output is correct
26 Correct 344 ms 340 KB Output is correct
27 Correct 283 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 288 ms 340 KB Output is correct
2 Correct 287 ms 340 KB Output is correct
3 Correct 204 ms 680 KB Output is correct
4 Execution timed out 4051 ms 3408 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 273 ms 340 KB Output is correct
2 Correct 455 ms 356 KB Output is correct
3 Correct 465 ms 340 KB Output is correct
4 Correct 306 ms 340 KB Output is correct
5 Execution timed out 4078 ms 3364 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 7 ms 316 KB Output is correct
4 Correct 7 ms 212 KB Output is correct
5 Correct 8 ms 212 KB Output is correct
6 Correct 287 ms 340 KB Output is correct
7 Correct 296 ms 340 KB Output is correct
8 Correct 136 ms 312 KB Output is correct
9 Correct 302 ms 340 KB Output is correct
10 Correct 277 ms 340 KB Output is correct
11 Correct 271 ms 340 KB Output is correct
12 Correct 265 ms 340 KB Output is correct
13 Correct 261 ms 340 KB Output is correct
14 Correct 127 ms 308 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 486 ms 348 KB Output is correct
18 Correct 462 ms 348 KB Output is correct
19 Correct 482 ms 340 KB Output is correct
20 Correct 465 ms 348 KB Output is correct
21 Correct 313 ms 340 KB Output is correct
22 Correct 471 ms 352 KB Output is correct
23 Correct 374 ms 340 KB Output is correct
24 Correct 357 ms 340 KB Output is correct
25 Correct 463 ms 348 KB Output is correct
26 Correct 344 ms 340 KB Output is correct
27 Correct 283 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 288 ms 340 KB Output is correct
30 Correct 287 ms 340 KB Output is correct
31 Correct 204 ms 680 KB Output is correct
32 Execution timed out 4051 ms 3408 KB Time limit exceeded
33 Halted 0 ms 0 KB -