cses

solution to cses exercise problems
git clone git://git.superpozycja.net/cses
Log | Files | Refs | README

tasks_and_deadlines.cpp (665B)


      1 #include <bits/stdc++.h>
      2 
      3 using namespace std;
      4 
      5 using ui = unsigned int;
      6 using l = long;
      7 using ul = unsigned long;
      8 using ll = long long;
      9 using ull = unsigned long long;
     10 
     11 using vi = vector<int>;
     12 using vui = vector<ui>;
     13 using vl = vector<l>;
     14 using vul = vector<ul>;
     15 using vll = vector<ll>;
     16 using vull = vector<ull>;
     17 
     18 void solve()
     19 {
     20 	int n;
     21 	cin >> n;
     22 	vector<pair<int, int>> t;
     23 	for (int i = 0; i < n; i++) {
     24 		int s, e;
     25 		cin >> s >> e;
     26 		t.push_back({s, e});
     27 	}
     28 	sort(t.begin(), t.end());
     29 	long res = 0, ti = 0;
     30 	for (auto x : t) {
     31 		ti += x.first;
     32 		res += x.second - ti;
     33 	}
     34 	cout << res << "\n";
     35 }
     36 
     37 int main()
     38 {
     39 	ios::sync_with_stdio(0);
     40 	cin.tie(0);
     41 	solve();
     42 }