# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1146319 | SmuggingSpun | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++20 | 0 ms | 328 KiB |
#include<bits/stdc++.h>
#define taskname "A"
using namespace std;
typedef long long ll;
const ll INF = 1e18;
template<class T>void minimize(T& a, T b){
if(a > b){
a = b;
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
int n, x;
cin >> n;
vector<int>d;
for(int i = 0, pre = 0; i < n; i++, pre = x){
cin >> x;
d.emplace_back(x - pre);
}
d.emplace_back(-x);
ll neg = 0, pos = 0, ans = INF;
for(int& x : d){
pos += max(0, x + 1);
}
for(int i = 0; i < n; i++){
pos -= max(0, d[i] + 1);
neg -= min(0, d[i] - 1);
minimize(ans, pos + neg);
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |