Submission #718068

#TimeUsernameProblemLanguageResultExecution timeMemory
718068niterGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms312 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]; if(n == 2){ if(arr[1] == arr[2]) cout << "1\n"; else cout << "0\n"; return 0; } // loop(i,1,n){ // b[i] = arr[i+1] - arr[i]; // cout << b[i] << " "; // } cout << endl; 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...