Submission #679947

#TimeUsernameProblemLanguageResultExecution timeMemory
679947redstonegamer22Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for(auto &e : a) cin >> e; int watered = 0; int l = 1, r = n - 2; while(l < r) { // cerr << l << " " << r << " " << watered << endl; while(l <= r && a[l] + watered > a[l - 1]) { a[l] += watered; l += 1; } while(r >= l && a[r] + watered > a[r + 1]) { a[r] += watered; r -= 1; } // cerr << l << " " << r << " " << watered << endl; if(r < l) break; // cerr << a[l - 1] << " " << a[l] << " " << a[r + 1] << " " << a[r] << endl; int next = min(a[l - 1] - (a[l] + watered) + 1, a[r + 1] - (a[r] + watered) + 1); watered += next; } for(int i = 0; i + 1 < a.size(); i++) if(a[i] == a[i + 1]) watered += 1; cout << watered << endl; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:29:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(int i = 0; i + 1 < a.size(); i++) if(a[i] == a[i + 1]) watered += 1;
      |                    ~~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...