Submission #773137

# Submission time Handle Problem Language Result Execution time Memory
773137 2023-07-04T15:42:10 Z raysh07 Snowball (JOI21_ho_t2) C++17
100 / 100
140 ms 11924 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18
#define f first
#define s second

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

const int N = 2e5 + 69;
int n, m;
int a[N], b[N], mn[N], mx[N];

void Solve()
{
	cin >> n >> m;

	for (int i = 1; i <= n; i++) cin >> a[i];

	for (int i = 1; i <= m; i++){
		cin >> b[i];
		b[i] += b[i - 1];
		mx[i] = max(mx[i - 1], b[i]);
		mn[i] = min(mn[i - 1], b[i]);
	}

	a[0] = -INF;
	a[n + 1] = INF;

	for (int i = 1; i <= n; i++){
		//check how much mn you can take 
		int l = 0, r = m, ans = 0;
		while (l != r){
			int mid = (l + r + 1) / 2;

			int p1 = a[i] + mn[mid];
			int p2 = a[i - 1] + mx[mid];

			if (p1 > p2) l = mid;
			else r = mid - 1;
		}

		ans += -mn[l];

		if (l != m){
			int change = b[l + 1] - b[l];
			change += b[l] - mn[l];
			
			if (change < 0){
				int p1 = a[i] + mn[l];
				int p2 = a[i - 1] + mx[l + 1];

				ans += min(-change, p1 - p2);
			}
		}

		l = 0, r = m;
		while (l != r){
			int mid = (l + r + 1)/2;

			int p1 = a[i] + mx[mid];
			int p2 = a[i + 1] + mn[mid];

			if (p1 < p2) l = mid;
			else r = mid - 1;
		}

		ans += mx[l];

		if (l != m){
			int change = b[l + 1] - b[l];
			change -= mx[l] - b[l];

			if (change > 0){
				int p1 = a[i] + mx[l];
				int p2 = a[i + 1] + mn[l + 1];

				ans += min(change, p2 - p1);
			}
		}

		cout << ans << "\n";
	}
}

int32_t main() 
{
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
  //  cin >> t;
    for(int i = 1; i <= t; i++) 
    {
        //cout << "Case #" << i << ": ";
        Solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 388 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 372 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 388 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 372 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 20 ms 7116 KB Output is correct
21 Correct 33 ms 6820 KB Output is correct
22 Correct 18 ms 6732 KB Output is correct
23 Correct 18 ms 6516 KB Output is correct
24 Correct 25 ms 6868 KB Output is correct
25 Correct 107 ms 11828 KB Output is correct
26 Correct 108 ms 11796 KB Output is correct
27 Correct 107 ms 11420 KB Output is correct
28 Correct 116 ms 11628 KB Output is correct
29 Correct 131 ms 11120 KB Output is correct
30 Correct 102 ms 10444 KB Output is correct
31 Correct 90 ms 9912 KB Output is correct
32 Correct 49 ms 10004 KB Output is correct
33 Correct 14 ms 1484 KB Output is correct
34 Correct 140 ms 11832 KB Output is correct
35 Correct 109 ms 11604 KB Output is correct
36 Correct 113 ms 11792 KB Output is correct
37 Correct 104 ms 11604 KB Output is correct
38 Correct 104 ms 11460 KB Output is correct
39 Correct 102 ms 11672 KB Output is correct
40 Correct 60 ms 11596 KB Output is correct
41 Correct 21 ms 7628 KB Output is correct
42 Correct 49 ms 10072 KB Output is correct
43 Correct 65 ms 11856 KB Output is correct
44 Correct 21 ms 7624 KB Output is correct
45 Correct 53 ms 11556 KB Output is correct
46 Correct 65 ms 11860 KB Output is correct
47 Correct 80 ms 11924 KB Output is correct
48 Correct 66 ms 11916 KB Output is correct