This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
#define clr(a, x) memset(a, x, sizeof(a))
#define dbg(x) cout<<"("<<#x<<"): "<<x<<endl;
#define printvector(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define all(v) v.begin(), v.end()
#define lcm(a, b) (a * b)/__gcd(a, b)
#define printvecpairs(vec) for(auto it: vec) cout<<it.fr<<' '<<it.sc<<endl;
#define endl '\n'
#define float long double
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
long long int delivery(int n, int k, int l, int positions[]) {
int tm_left[n+2], tm_right[n+2];
for(int i= 1;i<=n;i++){
int x= positions[i-1];
tm_left[i] = min(x*2, l);
int y = l-x;
tm_right[i] = min(y*2, l);
}
int dp[n+3][2];
clr(dp, 0);
for(int i= 1;i<=n;i++){
if(i > k){
dp[i][0] = dp[i-k][0] + tm_left[i];
} else {
dp[i][0] = tm_left[i];
}
}
int ans= INT_MAX;
for(int i= n;i>=1;i--){
if(i+k <= n){
dp[i][1] = dp[i+k][1] + tm_right[i];
} else {
dp[i][1] = tm_right[i];
}
ans = min(ans, dp[i][1]+dp[i-1][0]);
}
ans = min(ans, dp[n][0]);
return ans;
}
// signed main() {
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
// #ifdef LOCAL
// freopen("input.txt", "r", stdin);
// #endif
// int n, k, l;
// cin>>n>>k>>l;
// int pos[n];
// for(int i= 0;i<n;i++){
// cin>>pos[i];
// }
// delivery(n, k, l, pos);
// return 0;
// }
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |