Submission #694151

#TimeUsernameProblemLanguageResultExecution timeMemory
694151bdlGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
32 ms6184 KiB
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
using namespace std;

const int N = 2e5;

int main() {
  int n;
  scanf("%d", &n);
  static int a[N];
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  static long long l[N], r[N];
  for (int i = 0, x = 0; i < n; x = a[i++])
    l[i] = max(0, x - a[i] + 1) + (i > 0 ? l[i - 1] : 0);
  for (int i = n - 1, x = 0; i >= 0; x = a[i--])
    r[i] = max(0, x - a[i] + 1) + (i < n - 1 ? r[i + 1] : 0);
  long long x = 1e18;
  for (int i = 0; i < n; i++)
    x = min(x, max(l[i], r[i]));
  printf("%lld\n", x);
  return 0;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:11:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
Main.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%d", &a[i]);
      |     ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...