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)