Dang_Quan_10_Tin

Untitled

Jun 5th, 2020
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstdio>
  4. #define task "COVERING"
  5. using namespace std;
  6. using ll = long long;
  7. using ld = long double;
  8.  
  9. const int N = 1e5 + 2;
  10.  
  11. struct Trec{
  12.     ll w, h;
  13.     bool operator < (const Trec& a) const{
  14.         return w < a.w
  15.             ||(w == a.w && h < a.h);
  16.     }
  17. };
  18.  
  19. Trec a[N];
  20. int n;
  21. ll ans(0);
  22.  
  23. void Read(){
  24.     cin >> n;
  25.     for(int i = 1; i <= n; ++i){
  26.         cin >> a[i].w >> a[i].h;
  27.         a[i].w /= 2;
  28.         a[i].h /= 2;
  29.     }
  30.     sort(a + 1, a + n + 1);
  31. }
  32.  
  33. void Solve(){
  34.     ll piv = 1;
  35.     for(int i = n; i; --i){
  36.         if(a[i].h < piv)
  37.             continue;
  38.         ans += (a[i].h - piv + 1) * a[i].w;
  39.         piv = a[i].h + 1;
  40.     }
  41.     cout << ans * 4;
  42. }
  43.  
  44. main(){
  45.     ios::sync_with_stdio(0);
  46.     cin.tie(0);
  47.     cout.tie(0); if(fopen(task".INP", "r"))
  48.     freopen(task".INP", "r", stdin),
  49.     freopen(task".OUT", "w", stdout);
  50.     Read();
  51.     Solve();
  52. }
Advertisement
Add Comment
Please, Sign In to add comment