Submission #1092709

# Submission time Handle Problem Language Result Execution time Memory
1092709 2024-09-24T19:22:38 Z Seb Potatoes and fertilizers (LMIO19_bulves) C++17
34 / 100
57 ms 14972 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> //order_of_key = menores, find_by_order = consultar indexado en 0, regresa iterador
using ordered_set =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using vii = vector<int>;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());

#define mid ((l+r)>>1)
#define f first
#define s second
#define pb push_back
#define MP make_pair
#define all(x) (x).begin(),(x).end()
#define inicio(x) (*(x).begin())
#define rinicio(x) (*(x).rbegin())
#define SZ(x) (int)(x.size())

const ll MAXN = (ll)5e5 + 5;
const ll MOD = (ll)1e9 + 7;
const ll INF = (ll)1e12 + 5;
const ll OFFSET = (ll)1e6;

ll dp[2][MAXN];

void tc() {
    ll N, a, b, sum = 0, caso = 0; cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a >> b;
        a -= b;
        caso += a;
        if (i) {
            dp[0][i] = dp[0][i - 1] + abs(sum);
            dp[1][i] = min(dp[1][i - 1], dp[0][i - 1]) + abs(sum - 1);
        }
        sum += a;
    }
    if (caso) cout << min(dp[0][N - 1], dp[1][N - 1]) << "\n";
    else cout << dp[0][N - 1] << "\n";
    return;
}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; i++) {
        tc();
    }
    return 0;
}

//checa tus constantes, n = 1? overflow?
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 4 ms 1116 KB Output is correct
5 Correct 9 ms 1880 KB Output is correct
6 Correct 27 ms 6184 KB Output is correct
7 Correct 57 ms 14972 KB Output is correct
8 Correct 47 ms 12908 KB Output is correct
9 Correct 44 ms 12380 KB Output is correct
10 Correct 33 ms 10172 KB Output is correct
11 Correct 33 ms 10088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 4 ms 1116 KB Output is correct
5 Correct 9 ms 1880 KB Output is correct
6 Correct 27 ms 6184 KB Output is correct
7 Correct 57 ms 14972 KB Output is correct
8 Correct 47 ms 12908 KB Output is correct
9 Correct 44 ms 12380 KB Output is correct
10 Correct 33 ms 10172 KB Output is correct
11 Correct 33 ms 10088 KB Output is correct
12 Correct 14 ms 3932 KB Output is correct
13 Correct 33 ms 9040 KB Output is correct
14 Correct 55 ms 14896 KB Output is correct
15 Correct 46 ms 13136 KB Output is correct
16 Correct 49 ms 12372 KB Output is correct
17 Correct 34 ms 10068 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -