QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#384683 | #4500. Loop | Tobo# | AC ✓ | 84ms | 4660kb | C++20 | 1.2kb | 2024-04-10 09:45:13 | 2024-04-10 09:45:14 |
Judging History
answer
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#pragma GCC optimize(3, "inline")
using namespace std;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--)
{
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
if (k >= n - 1)
{
sort(a.begin(), a.end(), greater<>());
for (int i : a)
cout << i << ' ';
cout << '\n';
continue;
}
priority_queue<int> que;
for (int i = 0; i < n; i++)
{
if (que.size() < k)
que.push(a[i]), a[i] = 0;
else if (a[i] < que.top())
{
int cur = que.top();
que.pop();
swap(a[i], cur);
que.push(cur);
}
}
for (int i = 0; i < n; i++)
if (a[i])
cout << a[i] << ' ';
while (!que.empty())
{
cout << que.top() << ' ';
que.pop();
}
cout << '\n';
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 84ms
memory: 4660kb
input:
100 300000 300000 1 1 300000 153456 153456 1 153456 153456 300000 1 300000 1 300000 300000 300000 1 300000 300000 300000 1 300000 300000 300000 300000 300000 1 300000 153456 300000 1 153456 153456 1 300000 153456 300000 300000 1 300000 1 1 153456 153456 300000 153456 153456 153456 153456 1 300000 30...
output:
300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000...
result:
ok 100 lines