답안 #896310

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
896310 2024-01-01T08:24:15 Z thieunguyenhuy Potatoes and fertilizers (LMIO19_bulves) C++17
0 / 100
1 ms 2396 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long, long long>> vll;
typedef vector<pair<long long, int>> vli;
typedef vector<pair<int, long long>> vil;

#define bitcnt(n) __builtin_popcountll((n))
#define BIT(n, i) (((n) >> (i)) & 1ll)
#define FLIP(n, i) ((n) ^ (1ll << (i)))
#define MASK(i) (1ll << (i))
#define ON(n, i) ((n) | MASK(i))
#define OFF(n, i) ((n) & ~MASK(i))

#define Int __int128
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) a / gcd(a, b) * b
#define fi first
#define se second

template <class T1, class T2> 
bool maximize(T1 &x, T2 y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}
template <class T1, class T2>
bool minimize(T1 &x, T2 y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}

const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;

int n;
int a[N], b[N];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    cin >> n;

    for (int i = 1; i <= n; ++i) {
        cin >> a[i] >> b[i];
    }

    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
        if (a[i] >= b[i]) continue;
        else {
            for (int l = i - 1, r = i + 1; a[i] < b[i] && (l > 0 || r <= n); --l, ++r) {
                if (l > 0) {
                    int take = min(a[l] - b[l], b[i] - a[i]);
                    ans += 1ll * take * (i - l); a[l] -= take, a[i] += take;
                }
                if (a[i] >= b[i]) break;
                if (r <= n) {
                    int take = min(a[r], b[i] - a[i]);
                    ans += 1ll * take * (r - i); a[r] -= take, a[i] += take;
                }
            }
        } 
    }

    cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -