QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#56813#2375. Life Transferznk2373065134WA 2ms3612kbC++1.2kb2022-10-21 16:55:142022-10-21 16:55:16

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:55:16]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3612kb
  • [2022-10-21 16:55:14]
  • 提交

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, INF = 0x7fffffffffffffff;
ll n, k, lc, lm, pc, pm, pa, d, a[MAXN];
ll ans = INF, surplus, need, cnt;

void update(ll val, ll lim, int sgn) {
    if (val > lim) surplus += sgn * min(val - lim, d);
    else need += sgn * (lim - val);
    if (lim - val > d) {
        if (sgn == 1) cnt++;
        else 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];
        update(a[i], lm, 1);
    }
    if (surplus >= need && !cnt) ans = min(ans, n * pm + need * pa);
    std::sort(a + 1, a + n + 1);
    for (int i = 1, l = 1, r = n; i <= (n - 1) / k + 1; ++i, --r) {
        update(a[r], lm, -1);
        update(a[r], lc, 1);
        while (l < r && l <= i * (k - 1)) {
            update(a[l], lm, -1);
            update(a[l], 1, 1);
            ++l;
        }
        if (surplus >= need && !cnt) ans = min(ans, i * pc + max(0LL, n - i * k) * pm + need * pa);
    }
    if (ans == INF) ans = -1;
    cout << ans;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3612kb

input:

2 2
18 1000 16 1
5 3
16 15

output:

-1

result:

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