This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include "ricehub.h"
#include <cstdio>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define nl '\n'
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 1e5 + 10;
long long prefix[N];
int ans;
int besthub(int n, int maxL, int arr[], long long b){
// ios_base::sync_with_stdio(false);
// cin.tie(nullptr); cout.tie(nullptr);
for (int i = 0; i < n; i++) {
if(!i) {
prefix[i] = arr[i];
} else {
prefix[i] = prefix[i - 1] + arr[i];
}
}
int l = 0;
for(int r = 0; r < n; r++) {
int mid = (l + r) / 2;
long long cost = arr[mid] * (mid - l) - arr[mid] * (r - mid) + (prefix[r] - prefix[mid]) - (prefix[mid - 1] - prefix[l - 1]) ;
while(cost > b) {
l++, mid = (l + r) / 2, cost = arr[mid] * (mid - l) - arr[mid] * (r - mid) - (prefix[mid - 1] - prefix[l - 1]) + (prefix[r] - prefix[mid]);
}
if(cost <= b) {
ans = max(ans, r - l + 1);
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |