NC216174. Fightagainstinvolution
描述
MianKing chose a course in this semester. There are students in this course, and everyone needs to write a final paper. Let
denote the word count of the i-th student's final paper.
The i-th student has a lower bound and an upper bound
on the number of words in his final paper so that
The grade rule of this course is very amazing. The grade of the i-th student is
,
is the number of
satisfies that
.
Every student wants to achieve the highest possible grade, so under the optimal decision will equal to
for the i-th student.
But MianKing found an interesting thing: let's assume that . Under the optimal decision
are all equal to
and the grades of the students are all
. But if everyone only writes 1000 words in their final papers, their grades are still all
and they can use the time they save to play games.
Now to fight against involution, MianKing wants to decide 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 .
You need help MianKing calculate the minimum value of
输入描述
The first line has one integer.
Then there arelines, the i-th line has two integers
.
输出描述
Output the minimum value of.
示例1
输入:
3 1 10000 1 10000 1 10000
输出:
3
示例2
输入:
4 1 2 2 2 2 4 3 4
输出:
10
C++ 解法, 执行用时: 109ms, 内存消耗: 2080K, 提交时间: 2021-11-13 10:49:14
#include<bits/stdc++.h> using namespace std; long long n,temp,sum; struct node{ long long l,r; }a[100010]; bool cmp(node x,node y){ return x.r==y.r ? x.l>y.l : x.r<y.r; } int main(){ cin>>n; for(int i=0;i<n;i++) cin>>a[i].l>>a[i].r; sort(a,a+n,cmp); for(int i=0;i<n;i++){ temp = max(temp,a[i].l); sum += temp; } cout<<sum<<endl; }
pypy3(pypy3.6.1) 解法, 执行用时: 532ms, 内存消耗: 30144K, 提交时间: 2021-01-22 21:10:40
n = int(input()) stu = [] for i in range(n): a, b = map(int, input().split()) stu.append((a, b)) stu.sort(key=lambda x: (x[1], -x[0])) last = 0 ans = 0 for i in range(n): last = max(last, stu[i][0]) ans += last print(ans)