//
// main.cpp
// a.cpp
//
// Created by Juri Aljohani on 03/02/1444 AH.
//
//
// main.cpp
// a.cpp
//
// Created by Juri Aljohani on 03/02/1444 AH.
//
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#define int long long
using namespace std;
int a[200001], b[200001];
int mxa[200001], mxb[200001];
int ans[200001];
signed main () {
int n,q, mn = 0, mx = 0; cin >> n >> q;
map<int,int>s;
for(int i = 1; i <= n; i++) cin >> a[i];
vector<int>ss;
ss.push_back(0);
for(int i = 1; i <= q; i++) {
cin >> b[i];
b[i] += b[i - 1];
mn = min(mn, b[i]);
mx = max(mx, b[i]);
mxa[i] = max(mxa[i - 1], b[i]);
mxb[i] = min(mxb[i - 1], b[i]);
if(s[mxa[i] + abs(mxb[i])] == 0) {
s[mxa[i] + abs(mxb[i])] = i;
ss.push_back(mxa[i] + abs(mxb[i]));
}
}
sort(ss.begin(), ss.end());
ss.push_back(0);
for(int i = 1; i < n; i++){
int diff = a[i + 1] - a[i];
int f = lower_bound(ss.begin(), ss.end(), diff) - ss.begin();
int j = s[ss[f - 1]], k = s[ss[f]];
ans[i] += mxa[j];
ans[i + 1] = abs(mxb[j]);
if(mxa[k] > abs(mxb[k])){
ans[i] += (diff - (mxa[j] + abs(mxb[j])));
}else if(abs(mxb[k]) > mxb[k]){
ans[i + 1] += (diff - (mxa[j] + abs(mxb[j])));
}
}
ans[1] += abs(a[1] - (a[1] + mn));
ans[n] += abs(a[n] - (a[n] + mx));
for(int i = 1; i <= n; i++) cout << ans[i] << endl;
}
// zzzzzzzzzzxxxxxxxxxxccccccccccvvvvvvvvvvbbbbbbbbbbnnnnnnnnnnmmmmmmmmmmaaaaaaaaaassssssssssddddddddddfffffggggggggggghhhhhhhhhhjjjjjjjjjjkkkkkkkkkkllllllllllqqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrttttttttttyyyyyyyyyyuuuuuuuuuuiiiiiiiiiioooooooooopppppppppp1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
488 KB |
Output is correct |
2 |
Incorrect |
2 ms |
596 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
488 KB |
Output is correct |
2 |
Incorrect |
2 ms |
596 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |