# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1252471 | mingga | Snowball (JOI21_ho_t2) | C++20 | 84 ms | 6824 KiB |
// Author: caption_mingle
#include "bits/stdc++.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e9;
const int N = 2e5 + 7;
int n, q, a[N], lef[N], rig[N];
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#define task ""
if(fopen(task ".INP", "r")) {
freopen(task ".INP", "r", stdin);
freopen(task ".OUT", "w", stdout);
}
cin >> n >> q;
for(int i = 1; i <= n; i++) cin >> a[i];
int cur = 0;
for(int i = 1; i <= q; i++) {
int x; cin >> x;
cur += x;
lef[i] = min(lef[i - 1], cur);
rig[i] = max(rig[i - 1], cur);
}
lef[q + 1] = lef[q];
rig[q + 1] = rig[q];
for(int i = 1; i <= n; i++) {
int ans = 0;
if(i != n) {
int l = 0, r = q, lst = 0;
while(l <= r) {
int m = (l + r) >> 1;
if(a[i] + rig[m] <= a[i + 1] + lef[m]) {
l = m + 1;
lst = m;
} else r = m - 1;
}
if(lst == q) {
ans += rig[lst];
} else ans += max(rig[lst], a[i + 1] + lef[lst + 1] - a[i]);
} else ans += rig[q];
if(i != 1) {
int l = 0, r = q, lst = 0;
while(l <= r) {
int m = (l + r) >> 1;
if(a[i] + lef[m] >= a[i - 1] + rig[m]) {
l = m + 1;
lst = m;
} else r = m - 1;
}
if(lst == q) ans += abs(lef[lst]);
else ans += max(abs(lef[lst]), a[i] - a[i - 1] - rig[lst + 1]);
} else ans += abs(lef[q]);
cout << ans << ln;
}
cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |