C哪错了
  • 板块灌水区
  • 楼主HenryQ2022
  • 当前回复10
  • 已保存回复10
  • 发布时间2024/5/4 21:56
  • 上次更新2024/5/5 09:23:57
查看原帖
C哪错了
676590
HenryQ2022楼主2024/5/4 21:56
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;

#define int long long
#define N 200010
struct people {
    int head, str;
}p[N];
int n;
bool cmp(people x, people y) {
    if(x.str != y.str) {
        return x.str > y.str;//肩高的垫底
    } else {
        return x.head < y.head;//头高的放后面
    }
}
signed main()
{
    cin >> n;
    for(int i = 1;i <= n;i++) {
        cin >> p[i].str >> p[i].head;
    }
    sort(p + 1, p + n + 1, cmp);
    //加和
    int sum = 0;
    for(int i = 1;i < n/*不包括最后一个巨人*/;i++) {
        sum += p[i].str;
    }
    cout << sum + p[n].head << "\n";
    return 0;
}

样例全过

2024/5/4 21:56
加载中...