Submission #1146319

#TimeUsernameProblemLanguageResultExecution timeMemory
1146319SmuggingSpunGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
0 / 100
0 ms328 KiB
#include<bits/stdc++.h> #define taskname "A" using namespace std; typedef long long ll; const ll INF = 1e18; template<class T>void minimize(T& a, T b){ if(a > b){ a = b; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); } int n, x; cin >> n; vector<int>d; for(int i = 0, pre = 0; i < n; i++, pre = x){ cin >> x; d.emplace_back(x - pre); } d.emplace_back(-x); ll neg = 0, pos = 0, ans = INF; for(int& x : d){ pos += max(0, x + 1); } for(int i = 0; i < n; i++){ pos -= max(0, d[i] + 1); neg -= min(0, d[i] - 1); minimize(ans, pos + neg); } cout << ans; }

Compilation message (stderr)

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