Submission #940225

#TimeUsernameProblemLanguageResultExecution timeMemory
94022512345678Potatoes and fertilizers (LMIO19_bulves)C++17
0 / 100
3 ms604 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int nx=3e3+5, kx=20; ll n, a[nx], b[nx], ans, d[nx], dp[2][kx]; int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n; for (int i=1; i<=n; i++) cin>>a[i]>>b[i], d[i]=d[i-1]+a[i]-b[i]; for (int i=1; i<=n; i++) { int c=i%2, p=1-c; dp[c][0]=dp[p][0]+abs(d[i]); for (int j=1; j<=d[n]; j++) dp[c][j]=min(dp[c][j-1], dp[p][j]+abs(j-d[i])); //printf("%d %d %d\n", i, j, dp[c][j]); } cout<<dp[n%2][d[n]]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...