QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#421637 | #6525. New Houses | fuyouyufeng# | WA | 1ms | 3648kb | C++20 | 1.1kb | 2024-05-25 23:13:46 | 2024-05-25 23:13:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
#define int 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;
if (i == 1 && j * 2 <= m + 1)
ans = max(ans, s[i - 1] + vis);
else if (i - 1 + j * 2 <= m)
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: 1ms
memory: 3648kb
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'