Submission #1087060

#TimeUsernameProblemLanguageResultExecution timeMemory
1087060pokmui9909Sparklers (JOI17_sparklers)C++17
0 / 100
1 ms348 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; while(l > gl && B[l - 1] >= B[r]){ l--; ch = 1; } while(r < gr && B[l] >= B[r + 1]){ r++; 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; while(l < gl && B[l + 1] >= B[r]){ l++; ch = 1; } while(r > gr && B[l] >= B[r - 1]){ r--; 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...