QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#421637#6525. New Housesfuyouyufeng#WA 1ms3648kbC++201.1kb2024-05-25 23:13:462024-05-25 23:13:46

Judging History

你现在查看的是最新测评结果

  • [2024-05-25 23:13:46]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3648kb
  • [2024-05-25 23:13:46]
  • 提交

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'