This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define tobit(n) bitset<20>(n) //выводит 20 элементов в битовую систему
#define all(v) (v).begin(), (v).end()
#define rtt(v, k) rotate(v.begin(), v.begin() + k, v.end()); //move k elements back
signed main(){
int n, q; cin >> n >> q;
vector<int> v(n); //крч позиции снежков
for(auto& u : v) cin >> u;
vector<int> w(q), mx(q, -INT_MAX), mn(q, INT_MAX);
for(int i = 0; i < q; i++){
cin >> w[i]; //сила ветра
if(i != 0){
w[i] += w[i - 1];
mn[i] = min(w[i], mn[i - 1]); mx[i] = max(w[i], mx[i - 1]);
} else mn[i] = mx[i] = w[i];
} //ар бир снежоктун весин определеяем
for(int i = 0; i < n; i++){
int a = 0, b = q, res = 0, x, y;
//бин поиск кийинки кун снежный комго отуш учун
x = v[i]; y = (i + 1 != n ? v[i + 1] : INT_MAX);
while(abs(a - b) != 1){
int c = (a + b) / 2;
if(mx[c] + x < mn[c] + y) a = c;
else b = c;
} if(a != -1){
int cur = 0, t = a;
for(int j = 0; j + t < q && j < 5; j++){
int curr = min((y + mn[a]), (x + mx[a]));
cur = max(cur, min(curr - x, abs(x - y)));
a++;
} res += cur;
} a = 0; b = q;
//бин посик мурунку кунго снежный комго отуш учун
x = v[i]; y = (i != 0 ? v[i - 1] : -INT_MAX);
while(abs(a - b) != 1){
int c = (a + b) / 2;
if(mn[c] + x > mx[c] + y) a = c;
else b = c;
} if(a != -1){
int cur = 0, t = a;
for(int j = 0; j + t < q && j < 5; j++){
int curr = max((x + mn[a]), (y + mx[a]));
cur = max(cur, min(x - curr, abs(x - y)));
a++;
} res += cur; //cout << "b: " << mx[a] << " " << cur << "\n";
} //снежоктордун акыркы вестери
cout << res << "\n";
}
}
// NEED TO FAST CIN && COUT //
const int fastIO = [](){
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
return 0;
}();
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |