# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
973110 | hihihah | Potatoes and fertilizers (LMIO19_bulves) | C++14 | 134 ms | 262144 KiB |
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 ll long long
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
int n;
int a[500009];
int b[500009];
int64_t pre[500009];
void hihihah()
{
cin >> n;
for(int i = 1; i <= n; i ++)
cin >> a[i] >> b[i];
for(int i = 1; i <= n; i ++)
{
pre[i] = pre[i - 1] + a[i] - b[i];
}
vector<vector<int64_t>> dp(n + 3, vector<int64_t>(pre[n] + 3, 0));
for(int i = 1; i <= n; i ++)
{
for(int j = 0; j <= pre[n]; j ++)
{
dp[i][j] = dp[i - 1][j] + abs(j - pre[i]);
if(j > 0)
dp[i][j] = min(dp[i][j - 1], dp[i][j]);
}
}
cout << dp[n][pre[n]];
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
#define orz "mo"
if(fopen(orz".inp", "r"))
{
freopen(orz".inp", "r", stdin);
// freopen(orz".out", "w", stdout);
}
int t = 1;
// cin >> t;
while(t --)
{
hihihah();
}
return 0;
}
Compilation message (stderr)
# | 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... |