Submission #320567

#TimeUsernameProblemLanguageResultExecution timeMemory
320567arnold518Sparklers (JOI17_sparklers)C++14
100 / 100
36 ms2924 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 100000; const ll INF = 1e18; int N, K; ll T, A[MAXN+10], B[MAXN+10]; bool decide(ll X) { X*=2; if(T*X>(ll)1e9) return true; for(int i=1; i<=N; i++) B[i]=A[i]-i*T*X; int gl=1, gr=N; for(int i=1; i<=K; i++) if(B[gl]<=B[i]) gl=i; for(int i=K; i<=N; i++) if(B[gr]>=B[i]) gr=i; int l=K, r=K; ll lv=B[l], rv=B[r]; while(gl<=l || r<=gr) { int bl=l, br=r; for(; l>=gl && B[l]>=rv; l--) lv=max(lv, B[l]); for(; r<=gr && B[r]<=lv; r++) rv=min(rv, B[r]); if(l==bl && r==br) return false; } l=1, r=N; lv=B[l], rv=B[r]; while(l<=gl || gr<=r) { int bl=l, br=r; for(; l<=gl && B[l]>=rv; l++) lv=max(lv, B[l]); for(; r>=gr && B[r]<=lv; r--) rv=min(rv, B[r]); if(l==bl && r==br) return false; } return true; } int main() { scanf("%d%d%lld", &N, &K, &T); for(int i=1; i<=N; i++) scanf("%lld", &A[i]); ll lo=-1, hi=1e9+10; while(lo+1<hi) { ll mid=lo+hi>>1; if(decide(mid)) hi=mid; else lo=mid; } printf("%lld\n", hi); }

Compilation message (stderr)

sparklers.cpp: In function 'int main()':
sparklers.cpp:54:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   54 |   ll mid=lo+hi>>1;
      |          ~~^~~
sparklers.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   48 |  scanf("%d%d%lld", &N, &K, &T);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:49:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   49 |  for(int i=1; i<=N; i++) scanf("%lld", &A[i]);
      |                          ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...