呜呜呜萌新刚刚学C++,现在被一道题目卡住了,求助大佬
  • 板块P1392 取数
  • 楼主洛璟
  • 当前回复4
  • 已保存回复4
  • 发布时间2021/3/17 20:23
  • 上次更新2023/11/5 01:57:12
查看原帖
呜呜呜萌新刚刚学C++,现在被一道题目卡住了,求助大佬
198719
洛璟楼主2021/3/17 20:23

这是小蒟蒻的代码,调了很久没调出来,同学给的hack数据全过了,但是你谷一直全WA,求助qwq

#include<bits/stdc++.h>
using namespace std;
int n, m, k;
inline int read()
{
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c>'9')
    {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
    {
        x = (x << 3) + (x << 1) + (c ^ '0');
        c = getchar();
    }
    return x * f;
}
priority_queue<int, vector<int>, greater<int> >p, ans;
priority_queue<pair<int, int> >q;
int main()
{
    n = read();
    m = read();
    k = read();
    for (int j = 1;j <= m;++j)
    {
        int x = read();
        q.push(make_pair(-1, -x));
    }
    for (int i = 2;i <= n;++i)
    {
        for (int j = 1;j <= m;++j)
        {
            int x = read();
            p.push(x);
        }
        int x = -q.top().second;
        q.pop();
        int y = p.top();
        p.pop();
        q.push(make_pair(-i, -(x + y)));
        for (int j = 2;j <= k;++j)
        {
            int t1 = x + p.top();
            int t2 = y - q.top().second;
            if (t1 >= t2)
            {
                q.push(make_pair(-i, -t2));
                q.pop();
            }
            else
            {
                q.push(make_pair(-i, -t1));
                p.pop();
            }
        }
        while (-q.top().first == i - 1)
        {
            q.pop();
        }
        while (!p.empty())
        {
            p.pop();
        }
    }
    for (int i = 1;i <= k;++i)
    {
        ans.push(-q.top().second);
        q.pop();
    }
    for (int i = 1;i <= k;++i) {
        printf("%d ", ans.top()), ans.pop();
    }
    return 0;
}
2021/3/17 20:23
加载中...