Submission #814166

# Submission time Handle Problem Language Result Execution time Memory
814166 2023-08-08T05:57:41 Z MohamedAhmed04 Snowball (JOI21_ho_t2) C++14
100 / 100
480 ms 15328 KB
#include <bits/stdc++.h>

using namespace std ;

const int MAX = 2e5 + 10 ;

long long a[MAX] , b[MAX] ;
int n , q ;
long long pref[MAX] , mxpref[MAX] , mnpref[MAX] ;

bool check(int i , long long x)
{
	int l = 1 , r = q ;
	int idx = r+1 ;
	while(l <= r)
	{
		int mid = (l + r) >> 1 ;
		if(mxpref[mid] >= x - a[i])
			idx = mid , r = mid-1 ;
		else
			l = mid+1 ;
	}
	if(idx <= q && a[i+1] + mnpref[idx] >= x)
		return true ;
	else
		return false ;
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>q ;
	for(int i = 1 ; i <= n ; ++i)
		cin>>a[i] ;
	for(int i = 1 ; i <= q ; ++i)
		cin>>b[i] ;
	mnpref[0] = mxpref[0] = 0 ;
	for(int i = 1 ; i <= q ; ++i)
	{
		pref[i] = pref[i-1] + b[i] ;
		mxpref[i] = max(mxpref[i-1] , pref[i]) ;
		mnpref[i] = min(mnpref[i-1] , pref[i]) ;
	}
	a[0] = -2e18 , a[n+1] = 2e18 ;
	long long prv = -2e18 ;
	for(int i = 1 ; i <= n ; ++i)
	{
		long long ans = max(0ll , min(a[i] - prv , mnpref[q] * -1)) ;
		long long l = a[i] , r = a[i+1] ;
		long long last = a[i] ;
		while(l <= r)
		{
			long long mid = (l + r) >> 1ll ;
			if(check(i , mid))
				last = mid , l = mid+1ll ;
			else
				r = mid-1ll ;
		}
		ans += last - a[i] ;
		prv = last ;
		cout<<ans<<"\n" ;
	}
	return 0 ;
}		
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 4 ms 476 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 376 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 3 ms 464 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 4 ms 476 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 376 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 3 ms 464 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 20 ms 8652 KB Output is correct
21 Correct 20 ms 8512 KB Output is correct
22 Correct 20 ms 8204 KB Output is correct
23 Correct 22 ms 8112 KB Output is correct
24 Correct 67 ms 8520 KB Output is correct
25 Correct 452 ms 13436 KB Output is correct
26 Correct 476 ms 13360 KB Output is correct
27 Correct 439 ms 13024 KB Output is correct
28 Correct 428 ms 13196 KB Output is correct
29 Correct 381 ms 12652 KB Output is correct
30 Correct 211 ms 11980 KB Output is correct
31 Correct 52 ms 11436 KB Output is correct
32 Correct 57 ms 11620 KB Output is correct
33 Correct 37 ms 1620 KB Output is correct
34 Correct 416 ms 13776 KB Output is correct
35 Correct 422 ms 13184 KB Output is correct
36 Correct 480 ms 13424 KB Output is correct
37 Correct 444 ms 13112 KB Output is correct
38 Correct 463 ms 13008 KB Output is correct
39 Correct 437 ms 13156 KB Output is correct
40 Correct 131 ms 13196 KB Output is correct
41 Correct 22 ms 9276 KB Output is correct
42 Correct 93 ms 11588 KB Output is correct
43 Correct 145 ms 14948 KB Output is correct
44 Correct 25 ms 9428 KB Output is correct
45 Correct 236 ms 13204 KB Output is correct
46 Correct 149 ms 15052 KB Output is correct
47 Correct 135 ms 15328 KB Output is correct
48 Correct 128 ms 15296 KB Output is correct