답안 #1031980

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1031980 2024-07-23T09:22:31 Z mnieplowicz Snowball (JOI21_ho_t2) C++14
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;


int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n, q;
	cin >> n >> q;
	vector<long long> v(n), mini(q, 0ll), maxi(q, 0ll), Q(q);
	for(int i = 0; i < n; i++) cin >> v[i];
	long long sum = 0;
	for(int i = 0; i < q; i++){
		cin >> Q[i];
		sum += Q[i];
		if(i == 0){
			mini[i] = min(0ll, sum);
			maxi[i] = max(0ll, sum);
			continue;
		}
		mini[i] = min(mini[i - 1], sum);
		maxi[i] = max(maxi[i - 1], sum);
	}
	/*for(int i = 0; i <q; i++) cout << mini[i] << " ";
 	cout << '\n';
 	for(int i = 0; i <q; i++) cout << maxi[i] << " ";
 	cout << '\n';*/
	auto bs = [&](int i){
		int l = 0, r = q;
		while(l + 1 < r){
			int mid = (l + r) / 2;
			if(v[i + 1] - v[i] > maxi[mid] - mini[mid]) l = mid;
			else r = mid;
		}
		return l;
	};
	vector<long long> res(n);
	for(int i = 0; i < n - 1; i++){
		int x = bs(i);
		//cerr << i << ": " << x <<" " << mini[x] << " " << maxi[x]<< '\n';
		res[i] += maxi[x];
		res[i + 1] -= mini[x];
		long long dif = 0;
		if(x != q - 1) dif = v[i + 1] - v[i] - (maxi[x] - mini[x]);
		if(dif and Q[x + 1] > 0) res[i] += dif;
		if(dif and Q[x + 1] <= 0) res[i + 1] += dif;
		//cerr << res[i] << " " << res[i+1] << '\n';
	}
	res[0] -= mini[q - 1];
	res[n - 1] += maxi[q - 1];
	for(auto a : res) cout << a << '\n';	
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Incorrect 0 ms 344 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Incorrect 0 ms 344 KB Output isn't correct
15 Halted 0 ms 0 KB -