首页 > 其他分享 >Codeforces Round 892 (Div. 2) B. Olya and Game with Arrays

Codeforces Round 892 (Div. 2) B. Olya and Game with Arrays

时间:2023-10-17 20:45:06浏览次数:41  
标签:892 beauty min Arrays Olya int m1 数组 m2

一系列 \(n\) 个数组,第 \(i\) 个数组的大小 \(m_i \geq 2\) 。第 \(i\) 个数组为 \(a_{m_1}, a_{m_2}, \cdots, a_{m_i}\) 。

对于每个数组,你可以移动最多一个元素到另一个数组。

一系列 \(n\) 个数组的 \(beauty\) 定义为 \(\sum_{i=1}^{n} min_{j=1}^{m_i} a_{i, j}\) 。询问你经过若干操作后能够使这系列数组得到的最大美丽值,

一: \(min_{j=1}^{m_i} a_{i, j}\) 一定会对 \(beauty\) 产生贡献。假设是第 \(p\) 个数组。

二:除了第 \(p\) 个数组,所有数组都可以对 \(beauty\) 贡献次小值,然后将最小值移到数组 \(p\) 。\(min\ a_p\) 不会更小。

设第 \(i\) 个数组的最小值为 \(m1_i\) ,次小值为 \(m2_i\) 。

于是答案为 \(ans = \sum_{i=1}^{n} m2_i - min_{i=1}^{n} m2_i + min_{i=1}^{n} m1_i\) 。

view
#include <bits/stdc++.h>
typedef long long ll;
void solve(){
	int n; std::cin >> n;
	ll ans = 0;
	int mi_m1 = 1 << 30, mi_m2 = 1 << 30;
	for (int i = 1; i <= n; i++) {
		int m; std::cin >> m;
		int m1 = 1 << 30, m2 = 1 << 30;
		for (int i = 1; i <= m; i++) {
			int x; std::cin >> x;
			if (x <= m1) m2 = m1, m1 = x;
			else if (x <= m2) m2 = x;
		}
		mi_m1 = std::min(mi_m1, m1);
		mi_m2 = std::min(mi_m2, m2);
		ans += m2;
	}
	std::cout << ans - mi_m2 + mi_m1 << "\n";
}
int main() {
	int _ = 1; std::cin >> _;
	while (_--) {solve();}
	return 0;
}

标签:892,beauty,min,Arrays,Olya,int,m1,数组,m2
From: https://www.cnblogs.com/zsxuan/p/17768507.html

相关文章

  • Arrays、Lambda
    Array.sort()对对象进行排序Lambda        ......
  • [CF1158F]Density of subarrays
    F-Densityofsubarrays屲,平衡复杂度题首先考虑如何求一个序列的密度从最左端开始,找到需序列\(A[1...n]\)的最小段\(A[1...a_1]\),使其包含\(1\simc\)的所有颜色,然后又以\(a_1+1\)为起点,找下一个最短的包含\(1\simc\)的所有颜色的段,最后找到的这样的段的个数就是这个序列......
  • Go - Sorting Arrays or Slices
    Problem: Youwanttosortelementsinanarrayorslice.Solution: Forint,float64,andstringarraysorslicesyoucanusesort.Ints,sort.Float64s,andsort.Strings.Youcanalsouseacustomcomparatorbyusingsort.Slice.Forstructs,youcan......
  • Go - Making Arrays and Slices Safe for Concurrent Use
    Problem: Youwanttomakearraysandslicessafeforconcurrentusebymultiplegoroutines.Solution: Useamutexfromthesynclibrarytosafeguardthearrayorslice.Lockthearrayorslicebeforemodifyingit,andunlockitaftermodificationsarema......
  • CF1856B Good Arrays
    题意简述:给定一个序列\(a\),我们定义一个序列\(b\)是好的当且仅当对于\(1\dotsn\)内的每一个\(i\),\(a_i\neqb_i\)且\(\sum_{i=1}^na_i=\sum_{i=1}^nb_i\)(\(a_i\),\(b_i\)均为正整数)。现在有\(T\)组数据,每组数据给定\(n\)和序列\(a\),判断是否存在一个合法的序......
  • Go - Creating JSON Data Byte Arrays from Structs
    Problem: YouwanttocreateJSONdatafromastruct.Solution: Createthestructsthenusethejson.Marshalorjson.MarshalIndenttomarshalthedataintoaJSONsliceofbytes. funcmain(){person:=struct{}data,err:=......
  • Arrays常用方法
    1.Arrays.toString()方法方法作用:快速输出数组内容int[]a={1,2,3,4,5};System.out.println(Arrays.toString(a));//输出格式:[1,2,3,4,5]2.Arrays.sort()方法方法作用:给数组排序,默认升序int[]a=newint[5]{5,4,3,2,1};Arrays.sort(a);//12345System.out.printl......
  • Java Arrays.fill() 方法详解
    在Java编程中,数组是一个非常常见的数据结构,而Java提供了许多有用的数组操作方法来简化开发过程。其中之一是Arrays.fill()方法,它允许我们填充一个数组的所有元素,将它们设置为指定的值。在本篇文章中,我们将深入探讨Arrays.fill()方法的用法、参数和示例,以帮助您更好地理解和使用它。......
  • [892] Change the background color of a table in a Word document
    ref:python-docxChangingTableCellBackgroundColor.TochangethebackgroundcolorofatableinaWorddocumentusingPython,youcanusethepython-docxlibrary,whichallowsyoutocreateandmodifyWorddocumentsprogrammatically.Here'show......
  • Technocup 2022 - Elimination Round 2 Two Arrays
    给定两个数组\(a_1,a_2,\cdots,a_n\)和\(b_1,b_2,\cdots,b_n\)。定义\(a\)的一次操作:选择任意一个非负整数\(k(0\leqk\leqn)\)。选择任意\(k\)个独立的下标\(i_1\leqi_2\leq\cdots\leqi_k\leqn\)。对\(a_{i_1},a_{i_2},\cdots,a_{i_k}\)......