SHARE
TWEET

Untitled

a guest Aug 25th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5.  
  6. int n, b;
  7.  
  8. int sum(int k){ return 4*k*(n-k) + 1; }
  9.  
  10. int bin(int x, int l = 0, int r = n/2){
  11.   int mid;
  12.   while(l != r){
  13.     mid = (l+r)/2;
  14.     if(sum(mid) > x) r = mid;
  15.     else l = mid+1;
  16.   }
  17.   return max(l-1, 0ll);
  18. }
  19.  
  20. int32_t main(){
  21.   ios_base::sync_with_stdio(0), cin.tie(0);
  22.   cin >> n >> b;
  23.   int ax = bin(b);
  24.   pair<int, int> ld, rd, lu, ru;
  25.   ld = {ax + 1, ax + 1 };
  26.   rd = {ax + 1, n - ax };
  27.   lu = {n - ax, ax + 1 };
  28.   ru = {n - ax, n - ax };
  29.   int falta = b - sum(ax), sh = n-1-2*ax;
  30.   if(falta <= sh) cout << ld.first << " " << ld.second+falta << "\n";
  31.   else if(falta <= 2*sh) cout << rd.first + falta-sh << " " << rd.second << "\n";
  32.   else if(falta <= 3*sh) cout << ru.first << " " << ru.second - falta + 2*sh << "\n";
  33.   else cout << lu.first - falta + 3*sh << " " << lu.second << "\n";
  34. }
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