QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#721779#6770. Ants333zhanTL 0ms3532kbC++201.4kb2024-11-07 16:48:412024-11-07 16:48:42

Judging History

This is the latest submission verdict.

  • [2024-11-07 16:48:42]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 3532kb
  • [2024-11-07 16:48:41]
  • Submitted

answer

#include <bits/stdc++.h>
#define int long long

using namespace std;

constexpr int L = 1E9 + 1;

void solve () {
    int n, x, y;
    cin >> n >> x >> y;

    vector <int> a (n), d (n);
    for (int i = 0; i < n; i ++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i ++) {
        cin >> d[i];
    }

    int t = min (x, y) / n;
    int ans = t * L * 2;
    x -= t * n;
    y -= t * n;

    vector <pair <int, int>> b (n);
    for (int i = 0; i < n; i ++) {
        b[i].first = d[i] == 0 ? a[i] : (L - a[i]);
        b[i].second = d[i];
    }
    sort (b.begin (), b.end ());

    int num = n;
    while (num) {
        vector <pair <int, int>> nb;
        for (auto [c, o] : b) {
            if (o == 0) {
                if (x != 0) {
                    x --;
                    nb.push_back ({c, o ^ 1});
                } else {
                    num --;
                }
            } else {
                if (y != 0) {
                    y --;
                    nb.push_back ({c, o ^ 1});
                } 
            }
            if (num == 0) {
                cout << ans + c << '\n';
                return;
            }
        }
        ans += L;
        b = move (nb);
    }

    cout << ans << '\n';
}

signed main () {
    ios::sync_with_stdio (false);
    cin.tie (nullptr);

    int T = 1;
    // cin >> T;

    while (T --) {
        solve ();
    }

    return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3532kb

input:

2 2 4
2 3
0 1

output:

4000000001

result:

ok single line: '4000000001'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

1 1000000000 1000000000
500000000
0

output:

2000000002500000000

result:

ok single line: '2000000002500000000'

Test #3:

score: -100
Time Limit Exceeded

input:

1 1000000000 500000000
500000000
1

output:


result: