제출 #718080

#제출 시각아이디문제언어결과실행 시간메모리
718080niterGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
2 ms212 KiB
/// 2021 A #include <bits/stdc++.h> #define pii pair<int,int> #define loop(i,a,b) for(int i = a; i<b;i++) using namespace std; int arr[200005]; int b[200005]; //void db(){ // cout << "\n"; //} //template<class T, class ...U> //void db(T a, U ...b){ // cout << a << " "; db(b...); //} int main(){ // ios::sync_with_stdio(0); // cin.tie(0); int n, i; cin >> n; for (i=1; i<=n; i++) cin >> arr[i]; loop(i,1,n){ b[i] = arr[i+1] - arr[i]; } int cnt = 0, tmp; int l = 1, r = n-1; while(l < r){ while(b[l] > 0 && l < r){ l++; } if(!(l < r)) break; while(b[r] < 0 && l < r){ r--; } if(!(l < r)) break; tmp = min(abs(b[l]), abs(b[r])) + 1; b[l] += tmp; b[r] -= tmp; cnt += tmp; } if(b[l] == 0) cnt++; cout << cnt << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...