QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#56810#2375. Life Transferznk2373065134WA 3ms3704kbC++1.4kb2022-10-21 16:48:432022-10-21 16:48:45

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-21 16:48:45]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3704kb
  • [2022-10-21 16:48:43]
  • 提交

answer

#include <iostream>
#include <algorithm>
typedef long long ll;
using std::cin;
using std::cout;
using std::max;
using std::min;

const int MAXN = 1e5 + 10;
ll n, k, lc, lm, pc, pm, pa, d, a[MAXN];
ll ans = 0x7fffffffffffffff, surplus, need, cnt;
bool book[MAXN];

void update(ll i, ll lim, int sgn) {
    if (a[i] > lim) surplus += sgn * min(a[i] - lim, d);
    else need += sgn * (lim - a[i]);
    if (sgn == 1 && lim - a[i] > d) {
        book[i] = true;
        cnt++;
    }
    if (sgn == -1 && lim - a[i] > d) {
        book[i] = false;
        cnt--;
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> k >> lc >> pc >> lm >> pm >> pa >> d;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    std::sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; ++i) {
        update(i, lm, 1);
    }
    if (surplus >= need && !cnt) ans = min(ans, n * pm + need * pa);
    for (int i = 1, l = 1, r = n; i <= (n - 1) / k + 1; ++i, --r) {
        update(r, lm, -1);
        update(r, lc, 1);
        while (l < r && l <= i * (k - 1)) {
            update(l, lm, -1);
            update(l, 1, 1);
            ++l;
        }
        if (surplus >= need && !cnt) ans = min(ans, i * pc + max(0LL, n - i * k) * pm + need * pa);
    }
    if (ans == 0x7ffffffffffffff) ans = -1;
    cout << ans;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3704kb

input:

2 2
18 1000 16 1
5 3
16 15

output:

1010

result:

ok single line: '1010'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3476kb

input:

2 2
23 10 15 5
2 2
9 20

output:

9223372036854775807

result:

wrong answer 1st lines differ - expected: '-1', found: '9223372036854775807'