SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<vector>
  3. #include<fstream>
  4. #include<set>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. int main()
  10. {
  11.    
  12.    
  13.     //ifstream cin("input.txt");
  14.     //ofstream cout("output.txt");
  15.    
  16.    
  17.     int n;
  18.     cin >> n;
  19.     n = abs(n);
  20.     int i = 1, k =0;
  21.     while (k+i<=n)
  22.     {
  23.         k+=i;
  24.         i++;
  25.     }
  26.     if (k==n)cout<<i-1;
  27.     else cout<<i-1+min((n-k)*2, (k+i-n)*2+1);
  28.    
  29. }
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