Submission #512801

#TimeUsernameProblemLanguageResultExecution timeMemory
512801jesus_coconutGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
49 ms6176 KiB
#include <bits/stdc++.h> #define pb push_back #define eb emplace_back #define all(a) begin(a), end(a) #define F first #define S second using namespace std; using ll = long long; vector<ll> prefCost(vector<int> const &v) { vector<ll> ret(size(v)); int prev = v[0]; for (int i = 1; i < size(ret); ++i) { ret[i] = ret[i-1] + max(0ll, (ll)v[i-1] + 1 - v[i]); prev = max(prev + 1, v[i]); } return ret; } void solve() { int n; cin >> n; vector<int> v(n); for (auto &it : v) cin >> it; auto a = prefCost(v); reverse(all(v)); auto b = prefCost(v); reverse(all(b)); ll ans = LLONG_MAX; for (int i = 0; i < n; ++i) { ans = min(ans, max(a[i], b[i])); } cout << ans << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }

Compilation message (stderr)

Main.cpp: In function 'std::vector<long long int> prefCost(const std::vector<int>&)':
Main.cpp:15:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |   for (int i = 1; i < size(ret); ++i) {
      |                   ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...