Submission #783713

# Submission time Handle Problem Language Result Execution time Memory
783713 2023-07-15T08:50:19 Z boris_mihov Potatoes and fertilizers (LMIO19_bulves) C++17
0 / 100
495 ms 5508 KB
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>

typedef long long llong;
const int MAXN = 500000 + 10;
const int MAXAB = 30000 + 10;
const llong INF = 1e18;
const int INTINF = 1e9;

int abs(int num)
{
    if (num < 0) return -num;
    return num;
}

llong abs(llong num)
{
    if (num < 0) return -num;
    return num;
}

int n;
int sum;
int c[MAXN];
llong dp[2][20*MAXAB];

void solve()
{
    assert(sum > -MAXAB && sum < MAXAB);
    for (int i = 0 ; i < 20 * MAXAB ; ++i)
    {
        dp[(n + 1) & 1][i] = INF;
    }

    dp[(n + 1) & 1][10*MAXAB] = 0;
    for (int pos = n ; pos >= 1 ; --pos)
    {
        for (int bal = 11 * MAXAB - 1 ; bal > 9 * MAXAB ; --bal)
        {
            dp[pos & 1][bal] = INF;
            if (bal + 1 < 11 * MAXAB)
            {
                dp[pos & 1][bal] = dp[pos & 1][bal + 1];
            }

            dp[pos & 1][bal] = std::min(dp[pos & 1][bal], dp[(pos + 1) & 1][std::max(0, bal - c[pos])] + abs(bal - 10 * MAXAB));
        }
    }

    std::cout << dp[1][10*MAXAB] << '\n';
}

void input()
{
    std::cin >> n;
    for (int i = 1 ; i <= n ; ++i)
    {
        std::cin >> c[i];
        int val; std::cin >> val;
        c[i] -= val;
        sum += c[i];
    }
}

void fastIOI()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}

int main()
{
    fastIOI();
    input();
    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5460 KB Output is correct
2 Correct 495 ms 5508 KB Output is correct
3 Incorrect 388 ms 5460 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5460 KB Output is correct
2 Correct 495 ms 5508 KB Output is correct
3 Incorrect 388 ms 5460 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5460 KB Output is correct
2 Correct 495 ms 5508 KB Output is correct
3 Incorrect 3 ms 5460 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5460 KB Output is correct
2 Correct 495 ms 5508 KB Output is correct
3 Incorrect 388 ms 5460 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5460 KB Output is correct
2 Correct 495 ms 5508 KB Output is correct
3 Incorrect 388 ms 5460 KB Output isn't correct
4 Halted 0 ms 0 KB -