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;
}
相关推荐
吞下星星的少年·-·6 分钟前
牛客技能树:区间翻转
算法·滑动窗口
郝学胜-神的一滴1 小时前
中级OpenGL教程 022:探秘三维世界的血脉传承——物体父子关系与矩阵递归奥义
c++·线性代数·unity·矩阵·游戏引擎·unreal engine·opengl
拂拉氏1 小时前
【知识讲解】 链式哈希表的实现与unordered_map和unordered_set的封装
数据结构·哈希算法·散列表
haolin123.1 小时前
数据结构--二叉树
数据结构
tkevinjd1 小时前
力扣148-排序链表
算法·leetcode·链表
不如语冰1 小时前
AI大模型入门-参数的传递
数据结构·人工智能·pytorch·python
ch0sen1pm1 小时前
刚学完 CAS 原子操作,我花了一晚上写了三个无锁队列
c++
qeen871 小时前
【C++】vector的模拟实现详解(二)
c++·学习·算法·迭代器·stl
流浪0012 小时前
数据结构篇(四):线性表——链表——双链表
数据结构·链表
j7~2 小时前
【C++】C++ 继承全解析:从基本语法到菱形继承的底层原理
开发语言·c++·继承·组合·虚继承·#暑假·七月创作之星博客挑战赛