第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(济南)D-Fight against involution

题目

MianKing chose a course in this semester. There are nn students in this course, and everyone needs to write a final paper. Let w i w_i widenote the word count of the i-th student’s final paper.The i-th student has a lower bound L i L_i Liand an upper bound R i R_i Ri
on the number of words in his final paper so that L i ≤ w i L_i\leq w_i LiwiThe grade rule of this course is very amazing. The grade of the i-th student g i g_i giis n − K , K i n-K,Ki nK,Ki is the number of j ∈ [ 1 , n ] j \in [1,n] j[1,n] satisfies that w j > w i w_j>w_i wj>wiEvery student wants to achieve the highest possible grade, so under the optimal decision w i w_i wi will equal to R i R_i Rifor the i-th student.

But MianKing found an interesting thing: let’s assume that ∀ i ∈ [ 1 , n ] \forall i \in [1,n] i[1,n], L i = 1000 , R i = 10000 ∀ i ∈ [ 1 , n ] L_i=1000,R_i=10000∀i∈[1,n] Li=1000,Ri=10000i[1,n] Under the optimal decision w i w_i wiare all equal to 10000 and the grades of the students are all nn. But if everyone only writes 1000 words in their final papers, their grades are still all nn and they can use the time they save to play games.

Now to fight against involution, MianKing wants to decide w i w_i wi for each student, and his plan has to satisfy the following conditions:
For each student, his grade cannot be less than that in the original plan.
Minimize the sum of w i w_i wi
You need help MianKing calculate the minimum value of ∑ i = 1 n w i \sum_{i=1}^{n}w_i i=1nwi

The first line has one integer nn.

Then there are nn lines, the i-th line has two integers L i , R i L_i,R_i Li,Ri

1 ≤ n ≤ 1 0 5 1≤n≤10^5 1n105

1 ≤ L i ≤ R i ≤ 1 0 9 1\leq L_i\leq R_i\leq 10^9 1LiRi109
在这里插入图片描述

题意

期末写论文,每个人写论文的字数在 [ L , R ] [L,R] [L,R]之间,每个人的得分是 n − K n-K nK, K K K是比当前这个人的作业字数多的人数,每个人都想写尽可能多的字,这个现象被称为“内卷”。为了对抗内卷,我们需要最小化 W i W_i Wi的值。

思路

尽可能地让每个学生的 W i W_i Wi值相同,考虑贪心,先按照 R R R从小到大排序,如果 R R R相同再按照 L L L从大到小排序,这样就可以保证上一次选择的最大的 L L L尽可能多的在下面的区间内,这样我们就能选择最多的相同的 W i W_i Wi使得每个学生的得分最平均且最节省时间。

代码

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int maxn = 1e5+100;

class Stu 
{
	public:
		ll l,r;
}t[maxn];

bool cmp(Stu a,Stu b)
{
	return a.r==b.r?a.l>b.l:a.r<b.r;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld%lld",&t[i].l,&t[i].r);
	sort(t+1,t+1+n,cmp);
	
	ll ans = 0,L = 0;
	for(int i=1;i<=n;i++)
	{
		ans += max(L,t[i].l);
		L = max(L,t[i].l);
	}
	cout<<ans;
} 
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值