QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#660679 | #8548. China Convex Polygon Contest | hjxddl# | RE | 0ms | 0kb | C++20 | 1.6kb | 2024-10-20 12:40:28 | 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");
}
詳細信息
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