제출 #532478

#제출 시각아이디문제언어결과실행 시간메모리
532478chenyanGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
23 ms3440 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define pii pair<int,int> #define ff first #define ss second #define all(x) x.begin(),x.end() #define pb emplace_back #define N 200010 int a[N],d[N],su,s,ans=1e18; signed main(){ ios::sync_with_stdio(0); cin.tie(0); int n,i,j; cin>>n; for(i=0;i<n;i++) cin>>a[i]; for(i=1;i<n;i++){ d[i]=a[i]-a[i-1]; if(d[i]>=0) su+=d[i]+1; } ans=max(su,s); for(i=1;i<n;i++){ if(d[i]>=0) su-=d[i]+1; if(d[i]<=0) s+=-d[i]+1; ans=min(ans,max(su,s)); } cout<<ans<<'\n'; }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:14:10: warning: unused variable 'j' [-Wunused-variable]
   14 |  int n,i,j;
      |          ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...