Submission #603205

# Submission time Handle Problem Language Result Execution time Memory
603205 2022-07-23T17:04:14 Z Apiram Snowball (JOI21_ho_t2) C++14
100 / 100
160 ms 12856 KB
#include<bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n,m;cin>>n>>m;
	vector<long long>arr(n);
	for (int i = 0;i<n;++i){
		cin>>arr[i];
	}
	vector<long long>ans(n,0);
	vector<long long>pref_min(m + 1),pref_max(m + 1),pref(m + 1);
	pref_min[0] = 0;
	pref_max[0] = 0;
	pref[0]  = 0;
	for (int i = 0;i<m;++i){
		long long x;cin>>x;
		pref[i + 1]=x + pref[i];
		pref_max[i + 1] = pref[i + 1];
		pref_min[i + 1] = pref[i + 1];
	}
	for (int i = 0;i<m;++i){
		pref_min[i + 1] = min(pref_min[i],pref_min[i + 1]);
		pref_max[i + 1] = max(pref_max[i],pref_max[i + 1]);
	}
	for (int i = 0;i<n - 1;++i){
		int left = 0,right = m;
		int pos = m;
		while(left<=right){
			int mid = (left + right)>>1;
			if (arr[i] + pref_max[mid] >= arr[i + 1] + pref_min[mid]){
				right = mid - 1;
				pos = mid;
			}
			else left = mid + 1;
		}
		if (pref_max[pos] != pref[pos]){
			pos--;
		}
		//cout<<i<<" "<<pos<<'\n';
		long long temp = max(0LL,min(arr[i + 1] + pref_min[pos] - arr[i],pref_max[pos]));
		ans[i]+=temp;
		ans[i + 1]+=max(0LL,min(-pref_min[m],arr[i + 1] - temp - arr[i])); 
	}
	ans[n - 1]+=pref_max[m];
	ans[0]+=-pref_min[m];
	for (auto x:ans)cout<<x<<'\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 1 ms 468 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 2 ms 328 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 456 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 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 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 2 ms 328 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 456 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 27 ms 5304 KB Output is correct
21 Correct 25 ms 5292 KB Output is correct
22 Correct 29 ms 5292 KB Output is correct
23 Correct 24 ms 5432 KB Output is correct
24 Correct 28 ms 6480 KB Output is correct
25 Correct 99 ms 12624 KB Output is correct
26 Correct 105 ms 12588 KB Output is correct
27 Correct 99 ms 12488 KB Output is correct
28 Correct 99 ms 12376 KB Output is correct
29 Correct 101 ms 12220 KB Output is correct
30 Correct 85 ms 11872 KB Output is correct
31 Correct 67 ms 11424 KB Output is correct
32 Correct 56 ms 11412 KB Output is correct
33 Correct 9 ms 1620 KB Output is correct
34 Correct 109 ms 12592 KB Output is correct
35 Correct 160 ms 12368 KB Output is correct
36 Correct 101 ms 12684 KB Output is correct
37 Correct 95 ms 12500 KB Output is correct
38 Correct 109 ms 12376 KB Output is correct
39 Correct 123 ms 12452 KB Output is correct
40 Correct 70 ms 12464 KB Output is correct
41 Correct 28 ms 7704 KB Output is correct
42 Correct 57 ms 11368 KB Output is correct
43 Correct 91 ms 12648 KB Output is correct
44 Correct 38 ms 7576 KB Output is correct
45 Correct 73 ms 12448 KB Output is correct
46 Correct 85 ms 12856 KB Output is correct
47 Correct 97 ms 12696 KB Output is correct
48 Correct 91 ms 12772 KB Output is correct