Submission #1268930

#TimeUsernameProblemLanguageResultExecution timeMemory
1268930hoa208Growing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
15 ms3500 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++) #define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--) #define pa pair<ll, ll> #define fi first #define se second #define bit(mask, j) ((mask >> j) & 1) const ll mod = 1e9 + 7; const ll INF = 1e18; //-------------------------------------------------------------------- const ll N = 2e5 + 10; ll n, a[N], b[N]; void hbmt() { cin >> n; FOR(i, 1, n) { cin >> a[i]; } ll pre = a[1]; FOR(i, 2, n) { ll k = pre - a[i] + 1; k = max(0LL, k); b[i] = b[i - 1] + k; pre = a[i]; } ll ans = b[n]; pre = a[n]; ll cnt = 0; FORD(i, n - 1, 1) { ll k = pre - a[i] + 1; k = max(0LL, k); cnt += k; ans = min(ans, max(cnt, b[i])); pre = a[i]; } cout << ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); #define NAME "hbmt" if(fopen(NAME".inp", "r")) { freopen(NAME".inp", "r", stdin); freopen(NAME".out", "w", stdout); } //int t;cin>>t;while(t--) hbmt(); return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:47:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         freopen(NAME".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         freopen(NAME".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...