## 답안 #398603

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
398603 2021-05-04T15:23:32 Z AugustinasJucas 쌀 창고 (IOI11_ricehub) C++14
17 / 100
1000 ms 125008 KB
```#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
int n, l;
const int dydis = 1e5 + 10;
long long pref[dydis];
long long sm(int l, int r){
return pref[r] - (l == 0 ? 0ll : pref[l-1]);
}
map<int, int> kek;
pair<long long, long long> f(int dst, int ind, int mas[], long long B){
int l = 0; int r = ind-1; int mid;
int L = ind; int R = ind;
while(l <= r){
mid = (l + r) / 2;
if(abs(mas[mid]-mas[ind]) < dst){
L = min(L, mid);
r = mid-1;
}else{
l = mid+1;
}
}
l = ind+1; r = n-1;
while(l <= r){
mid = (l + r) / 2;
if(abs(mas[mid] - mas[ind]) < dst){
R = max(R, mid);
l = mid+1;
}else{
r = mid-1;
}
}

long long SL = 1ll * (ind - L + 1) * mas[ind] - sm(L, ind);
long long SR = sm(ind, R) - 1ll * (R - ind + 1) * mas[ind];

long long lieka = B - SL - SR;
int pl = 0;
if(lieka > 0){
int galiu = lieka / dst;
galiu = min(galiu, kek[mas[ind] + dst] + kek[mas[ind] - dst]);
pl = galiu;
}

// cout << "SR = " << sm(ind, R) << " - " << 1ll * (R - ind + 1) * mas[ind] << ", MAS[" << ind << "] = " << mas[ind] << "    ";
//  cout << "dst = " << dst << ", o i = " << ind << ", tai L = " << L << ", R = " <<  R << ", tai ret = " << SL << " + " << SR << endl;
return make_pair(pl + SL + SR, R - L + 1);
}
int besthub(int N, int L, int X[], long long B) {
n = N; l = L;
for(int i = 0; i < n; i++) kek[X[i]]++;
for(int i = 0; i < n; i++) pref[i] = 1ll * X[i] + (i == 0 ? 0ll : pref[i-1]);
long long ans = 0;
for(int i = 0; i < n; i++){
long long st = 1;
int l = 0, r = 1e9, mid;
while(l <= r){
mid = (l + r) / 2;
auto ff = f(mid, i, X, B);
if(ff.first <= B){
st = max(st, ff.second);
l = mid+1;
}else{
r = mid-1;
}
}
// cout << "i = " << i << ", st = " << st << endl;
ans = max(ans, st);
}
return ans;
}```

#### Subtask #1 17.0 / 17.0

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 204 KB Output is correct

#### Subtask #2 0 / 25.0

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 352 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Incorrect 1 ms 204 KB Output isn't correct
12 Halted 0 ms 0 KB -

#### Subtask #3 0 / 26.0

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 14 ms 2924 KB Output is correct
4 Correct 6 ms 1100 KB Output is correct
5 Incorrect 2 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -

#### Subtask #4 0 / 32.0

# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 3440 KB Output is correct
2 Correct 73 ms 3396 KB Output is correct
3 Execution timed out 1086 ms 125008 KB Time limit exceeded
4 Halted 0 ms 0 KB -