Codeforces Round #513 d-social Circles (greedy)

Source: Internet
Author: User

Main topic:

There were n (n≤105) individuals in a circle, and the first person asked to empty Li's seat on the left, and the right to Empty ri (li,ri≤109) seats. Ask for the minimum number of seats to be arranged.
Ideas:

First of all, let's assume everybody's li+ri+1.
A location. Consider how to arrange the order of neighboring people and merge the Li,ri of neighboring people to make the answer optimal.
All Li,ri are sorted separately, and the corresponding Li,ri
The merger must be optimal (think about why).


#include <iostream>#include<iomanip>#include<algorithm>#include<map>#include<vector>#include<string>#include<Set>#include<cmath>using namespaceStd;typedefLong Longll;Const intMAXN =100100;intN;intL[MAXN], R[MAXN];intMain () {Ios_base::sync_with_stdio (0);    Cin.tie (NULL); CIN>>N;  for(inti =0; i < N; i++) Cin>> L[i] >>R[i]; Sort (L, l+N); Sort (R, R+N); ll ans=N;  for(inti =0; i < N; i++) ans+=Max (L[i], r[i]); cout<< ans <<"\ n";}

Codeforces Round #513 d-social Circles (greedy)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.