QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#660679#8548. China Convex Polygon Contesthjxddl#RE 0ms0kbC++201.6kb2024-10-20 12:40:282024-10-20 12:40:28

Judging History

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

  • [2024-10-20 12:40:28]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-20 12:40:28]
  • 提交

answer

// Coded by hjxddl
#include <bits/stdc++.h>
#define ll long long
#define db double
const int N = 2e5 + 5;
void solve() {
    ll n, m;
    std::cin >> n >> m;
    std::vector<ll> a(n + 5), b(n + 5);
    for (int i = 1; i <= n; i++)
        std::cin >> a[i];
    for (int i = 1; i <= n; i++)
        std::cin >> b[i];
    a[n + 1] = m;
    std::sort(b.begin() + 1, b.begin() + n + 1);
    for (int i = 1; i <= n; i++) {
        b[i] += b[i - 1];
        // std::cout << b[i] << " ";
    }
    // std::cout << '\n';
    std::priority_queue<ll> q;
    int j = n;
    while (b[j] > m) j--;
    ll ans = 0;
    for (int i = n; i >= 1; i--) {
        bool vis = 0;
        while (q.size() && j > 1 && a[i] <= b[j - 1]) {
            ans += q.top();
            q.pop();
            j--;
        }
        if (a[i] > b[j])
            q.push(a[i + 1] - a[i]);
        else {
            if (q.size() && a[i + 1] - b[j] < q.top()) {
                ans += q.top();
                q.pop();
                q.push(a[i + 1] - a[i]);
                j--;
            } else {
                ans += a[i + 1] - b[j];
                if (q.size()) {
                    int x = q.top() + b[j] - a[i];
                    q.pop();
                    q.push(x);
                }
                j--;
            }
        }
    }
    std::cout << ans << '\n';
}
int main() {
    std::ios::sync_with_stdio(0);
    std::cin.tie(0), std::cout.tie(0);
    int t = 1;
    std::cin >> t;
    while (t--) {
        solve();
    }
    std::cout << std::flush;
    system("pause");
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

3
3 10
1 5 9
1 2 3
3 10
1 5 9
1 1 4
3 10
1 5 9
1 5 10

output:

9
9
7

result: