Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
2018JanSilv2
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<double, double> pd; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pi> vpi; #define min3(a, b, c) min(a, min(b, c)) #define max3(a, b, c) max(a, max(b, c)) #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define p1 first #define p2 second const double PI = 4 * atan(1); const int MOD = 1000000007; const ll LINF = 1ll << 60; const int INF = 1 << 30; // ofstream fout ("lifeguards.out"); // ifstream fin ("lifeguards.in"); #define fin cin #define fout cout int N; pi l[100005]; vi ans; int main() { // cin >> N; for (int i = 0; i < N; i++) { cin >> l[i].p1 >> l[i].p2; } sort(l, l + N); int tot = l[0].p2 - l[0].p1; for (int i = 1; i < N; i++) { tot += l[i].p2 - l[i].p1 - max(0, l[i - 1].p2 - l[i].p1); } ans.pb(l[0].p2 - l[0].p1 - max(0, l[0].p2 - l[1].p1)); for (int i = 1; i < N - 1; i++) { ans.pb(max(l[i].p1, l[i - 1].p2), min(l[i].p2, l[i + 1].p1)); } ans.pb(l[N - 1].p2 - l[N - 1].p1 - max(0, l[N - 2].p2 - l[N - 1].p1)); cout << tot - *min_element(ans.begin(), ans.end()) << endl; return 0; } /* did u get back ok r ur parents mad :( sigh issok u dont needa care abt me lol i got rly depressed halfway home and i almost started crying haha sigh :( */
run
|
edit
|
history
|
help
0
NameTempSpecial
nearest
count common elements in three sorted array without using extraspace
series kv type 1
area of a circle using pointer
Question 1
LALALALALALLLLAAA
vem de livezada
Motsow
staticfun