Submission #1087073

#TimeUsernameProblemLanguageResultExecution timeMemory
1087073pokmui9909Sparklers (JOI17_sparklers)C++17
100 / 100
28 ms3052 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; ll N, K, T, A[100005], B[100005]; bool f(ll v){ for(ll i = 1; i <= N; i++){ B[i] = A[i] - 2 * v * T * i; } ll gl = K, gr = K; for(ll i = 1; i <= N; i++){ if(i <= K && B[gl] <= B[i]) gl = i; if(i >= K && B[gr] >= B[i]) gr = i; } ll l = K, r = K; while(1){ ll ch = 0, nl = l, nr = r; while(nl > gl && B[nl - 1] >= B[r] && (nl == l || B[nl] < B[l])) nl--; if(B[nl] >= B[l] && nl < l){ l = nl, ch = 1; } while(nr < gr && B[nr + 1] <= B[l] && (nr == r || B[nr] > B[r])) nr++; if(B[nr] <= B[r] && nr > r){ r = nr, ch = 1; } if(ch == 0) break; } if(l != gl || r != gr) return 0; l = 1, r = N; if(B[l] < B[r]) return 0; while(1){ ll ch = 0, nl = l, nr = r; while(nl < gl && B[nl + 1] >= B[r] && (nl == l || B[nl] < B[l])) nl++; if(B[nl] >= B[l] && nl > l){ l = nl, ch = 1; } while(nr > gr && B[nr - 1] <= B[l] && (nr == r || B[nr] > B[r])) nr--; if(B[nr] <= B[r] && nr < r){ r = nr, ch = 1; } if(ch == 0) break; } return (l == gl && r == gr); } int main(){ cin.tie(0) -> sync_with_stdio(0); cin >> N >> K >> T; for(ll i = 1; i <= N; i++){ cin >> A[i]; } if(A[N] == 0){ cout << 0; return 0; } ll L = 1, R = 1e9; while(L <= R){ ll m = (L + R) / 2; if(f(m)) R = m - 1; else L = m + 1; } cout << L; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...