Submission #377667

#TimeUsernameProblemLanguageResultExecution timeMemory
377667LawlietGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
36 ms2028 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int lli; typedef pair<int,int> pii; const int MAXN = 200010; const int INF = 1000000010; const lli INFLL = 1000000000000000010; int v[MAXN]; int diff[MAXN]; void solveTestCase(int testCase) { int n; scanf("%d",&n); for(int i = 1 ; i <= n ; i++) scanf("%d",&v[i]); for(int i = 1 ; i < n ; i++) diff[i] = v[i + 1] - v[i]; lli ans = INFLL; lli ansLeft = 0; lli ansRight = 0; for(int i = 1 ; i < n ; i++) if( diff[i] >= 0 ) ansRight += diff[i] + 1; for(int i = 1 ; i <= n ; i++) { lli curAns = max( ansLeft , ansRight ); ans = min( ans , curAns ); if( diff[i] >= 0 ) ansRight -= diff[i] + 1; if( diff[i] <= 0 ) ansLeft += -diff[i] + 1; } printf("%lld\n",ans); } int main() { int qtdTestCases = 1; // scanf("%d",&qtdTestCases); for(int testCase = 1 ; testCase <= qtdTestCases ; testCase++) solveTestCase( testCase ); }

Compilation message (stderr)

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