QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#421611 | #6525. New Houses | fuyouyufeng# | WA | 0ms | 3852kb | C++20 | 1.0kb | 2024-05-25 22:20:11 | 2024-05-25 22:20:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
#define int unsigned long long
typedef pair<int, int> PII;
PII e[N];
#define x first
#define y second
bool cmp(PII a, PII b)
{
if (a.y < b.y)
return true;
else if (a.y == b.y)
return a.x > b.x;
}
void solve()
{
int n, m;
cin >> n >> m;
vector<int> s(n + 1, 0);
for (int i = 1; i <= n; i++)
cin >> e[i].x >> e[i].y;
sort(e + 1, e + 1 + n, cmp);
for (int i = 1; i <= n; i++)
s[i] = s[i - 1] + e[i].x;
int ans = s[n];
if (m == n)
{
cout << ans << '\n';
return;
}
int vis = 0;
for (int i = n, j = 1; i >= 1, j <= n; i--, j++)
{
vis += e[i].y;
int r = m - (j - 1) * 2;
if (r > i - 1)
{
ans = max(ans, s[i - 1] + vis);
}
}
cout << ans << '\n';
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3852kb
input:
3 4 5 1 100 100 1 100 1 100 1 2 2 1 10 1 10 2 3 100 50 1 1000
output:
400 2 1100
result:
wrong answer 3rd numbers differ - expected: '1050', found: '1100'