daily pastebin goal
50%
SHARE
TWEET

PYRAMID

Taksh Dec 14th, 2017 (edited) 18 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5. long long n;
  6.  
  7. int main()
  8. {
  9.     ios_base::sync_with_stdio(false);
  10.     cin.tie(NULL);
  11.     cin >> n;
  12.     long long *first = new long long[n];
  13.     long long *second = new long long[n];
  14.     long long *least = new long long[n];
  15.     for (long long i = 0; i < n; ++i)
  16.     {
  17.         cin >> first[i] >> second[i];
  18.         least[i] = min(first[i], second[i]);
  19.     }
  20.     sort(least, least + n);
  21.     long long answer = 0;  
  22.     long long length = 0;   // minimum dimension required for certain height
  23.     long long j = 0;    // to iterate between sorted least dimensions
  24.     while (j < n)
  25.     {
  26.         if (length <= least[j])
  27.         {
  28.             answer = length;
  29.             ++length;
  30.             ++j;
  31.         }
  32.         else
  33.         {
  34.             ++j;
  35.         }
  36.     }
  37.     cout << answer;
  38.     return 0;
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top