QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#766668 | #6525. New Houses | diguo | WA | 0ms | 3460kb | C++20 | 1.5kb | 2024-11-20 18:09:34 | 2024-11-20 18:09:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(x, y) x.begin() + y, x.end()
#define mkp make_pair
#define pii pair<int, int>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pll pair<long long, long long>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define rep(name, base, limit) for(int name = base; name <= limit; ++name)
#define per(name, base, limit) for(int name = base; name >= limit; --name)
#define lowbit(x) ((x) & -(x))
#define ls(p) ((p) << 1)
#define rs(p) ((p) << 1 | 1)
const int INF = 0x3f3f3f3f;
const long long LNF = 0x3f3f3f3f3f3f3f3f;
inline long long read()
{
long long x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
return x*f;
}
void solve()
{
int n = read(), m = read(), k = m - n;
vector<ll> a(n + 1), b(n + 1);
ll ans = 0;
ll now = 0;
rep(i, 1, n) a[i] = read(), b[i] = read(), now += b[i];
priority_queue<ll> pq;
rep(i, 1, n) pq.push(a[i] - b[i]);
if (n * 2 - 1 >= m) ans = max(ans, now);
now += pq.top();
pq.pop();
rep(i, 2, n)
{
now += pq.top();
pq.pop();
if (2 * n - i <= m) ans = max(ans, now);
}
cout << ans;
}
// 1111 1
// 111 1 1
// 11 1 1 1
// 1 1 1 1 1
// 11 1 1 1
// m - n;
int main()
{
int t = read();
while (t--)
{
solve();
if (t) putchar('\n');
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3460kb
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 20 1050
result:
wrong answer 2nd numbers differ - expected: '2', found: '20'