Submission #1106625

# Submission time Handle Problem Language Result Execution time Memory
1106625 2024-10-30T17:53:53 Z Canuc80k Potatoes and fertilizers (LMIO19_bulves) C++17
20 / 100
77 ms 1272 KB
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

const ll N = 3e3 + 1;
const ll M = 1e9 + 7;

ll n;
ll a[N], b[N], d[N];
ll f[(ll)3e4 + 1], of[(ll)3e4 + 1];

void doTest(ll testID) {
    cin >> n; ll sum = 0;
    for (int i = 1; i <= n; i ++) {
        cin >> a[i] >> b[i];
        d[i] = d[i - 1] + a[i] - b[i];
    }
    memset(f, 0x3f, sizeof f);

    of[0] = 0;
    for (int i = 1; i <= n; i ++) {
        for (int j = 0; j <= d[n]; j ++) {
            if (j != 0) f[j] = f[j - 1];
            f[j] = min(f[j], of[j] + abs(d[i] - j)); 
            // cout << "Debug: " << i << ' ' << j << ' ' << f[j] << ' ' <<  << endl; 
        }
        for (int j = 0; j <= d[n]; j ++) {
            of[j] = f[j];
            f[j] = 1e18;
        }
    }

    cout << of[d[n]];
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);

    int test = 1; 
    // cin >> test;
    for (int _ = 1; _ <= test; _ ++) doTest(_);
}

Compilation message

bulves.cpp: In function 'void doTest(ll)':
bulves.cpp:15:18: warning: unused variable 'sum' [-Wunused-variable]
   15 |     cin >> n; ll sum = 0;
      |                  ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Incorrect 1 ms 592 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Incorrect 1 ms 592 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 4 ms 592 KB Output is correct
5 Correct 16 ms 592 KB Output is correct
6 Correct 77 ms 884 KB Output is correct
7 Correct 1 ms 760 KB Output is correct
8 Correct 7 ms 792 KB Output is correct
9 Correct 7 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 4 ms 592 KB Output is correct
6 Correct 16 ms 592 KB Output is correct
7 Correct 77 ms 884 KB Output is correct
8 Correct 1 ms 760 KB Output is correct
9 Correct 7 ms 792 KB Output is correct
10 Correct 7 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Runtime error 3 ms 1272 KB Execution killed with signal 11
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 4 ms 592 KB Output is correct
6 Correct 16 ms 592 KB Output is correct
7 Correct 77 ms 884 KB Output is correct
8 Correct 1 ms 760 KB Output is correct
9 Correct 7 ms 792 KB Output is correct
10 Correct 7 ms 592 KB Output is correct
11 Incorrect 1 ms 592 KB Output isn't correct
12 Halted 0 ms 0 KB -