CCF201909_1

题解:

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;

struct tree {
	int id;
	int apple;
	int cut = 0;
};

bool cmp(tree a, tree b)
{
	if (a.cut == b.cut)
	{
		return a.id < b.id;
	}
	return a.cut > b.cut;
}

int main()
{
	int n, m;
	cin >> n >> m;
	tree t[n];
	int cutNum = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> t[i].apple;
		t[i].id = i + 1;
		for (int j = 0; j < m; j++)
		{
			cin >> cutNum;
			t[i].cut += (-cutNum);
		}
		t[i].apple -= t[i].cut;
	}
	int sum = 0;
	sort(t, t + n, cmp);
	for (int i = 0; i < n; i++)
	{
		sum += t[i].apple;
	}
	cout << sum << " " << t[0].id << " " << t[0].cut << endl;
	return 0;
}
相关推荐
cc.ChenLy2 小时前
算法从入门到精通实战指南
算法
王老师青少年编程8 小时前
2026年6月GESP真题及题解(C++一级):交税
c++·题解·真题·gesp·一级·2026年6月·交税
Jerry8 小时前
LeetCode 160. 相交链表
算法
Jerry9 小时前
LeetCode 19. 删除链表的倒数第 N 个结点
算法
金銀銅鐵9 小时前
费马小定理
python·数学·算法
技术不好的崎鸣同学10 小时前
[ACTF2020 新生赛]Exec 思路及解法
算法·安全·web安全
Full Stack Developme11 小时前
Java LRU 与 LFU 算法及应用
java·开发语言·算法
Jerry13 小时前
LeetCode 707. 设计链表
算法
疋瓞13 小时前
python和C++对比(1)_数据类型和数据结构
数据结构·c++·python