Submission #717989

#TimeUsernameProblemLanguageResultExecution timeMemory
717989vinnipuh01Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
93 ms7100 KiB
#include <iostream> #include <bits/stdc++.h> #include <cmath> #include <algorithm> #include <vector> #include <deque> #include <set> #include <stack> #include <string> #include <map> #include <queue> #define int long long #define sqrt sqrtl using namespace std; const long long oo = 1000000000000000000; long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos; /* ViHHiPuh (( `'-""``""-'` )) )-__-_.._-__-( / --- (o _ o) --- \ \ .-* ( .0. ) *-. / _'-. ,_ '=' _, .-'_ / `;#'#'# - #'#'#;` \ \_)) -----'#'----- ((_/ # --------- # '# ------- ------ #' /..-'# ------- #'-.\ _\...-\'# -- #'/-.../_ ((____)- '#' -(____)) cout << fixed << setprecision(6) << x; ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); freopen ( "sum.in", "r", stdin ) */ int n, a[ 200001 ], b[ 200001 ]; int p[ 200002 ], sf[ 200002 ]; main () { cin >> n; for ( int i = 1; i <= n; i ++ ) { cin >> a[ i ]; b[ i ] = a[ i ]; } for ( int i = n; i >= 1; i -- ) { p[ i ] = p[ i + 1 ]; b[ i ] += p[ i ]; if ( i < n ) { if ( b[ i + 1 ] >= b[ i ] ) { p[ i ] += b[ i + 1 ] - b[ i ] + 1; b[ i ] = b[ i + 1 ] + 1; } } } ans = oo; for ( int i = 1; i <= n; i ++ ) { a[ i ] += sum; if ( a[ i ] <= a[ i - 1 ] ) { sum += a[ i - 1 ] - a[ i ] + 1; a[ i ] = a[ i - 1 ] + 1; } else num = 0; // cout << i << " - " << sum << " " << p[ i ] << "\n"; ans = min( ans, sum + max( 0ll, p[ i ] - sum ) ); } cout << ans; } /* 1 - kick x 2 - kick y 0 - go */

Compilation message (stderr)

Main.cpp:50:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   50 | main () {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...