fork(1) download
  1. #include <map>
  2. #include <cmath>
  3. #include <ctime>
  4. #include <deque>
  5. #include <queue>
  6. #include <stack>
  7. #include <cctype>
  8. #include <cstdio>
  9. #include <string>
  10. #include <vector>
  11. #include <climits>
  12. #include <cstdlib>
  13. #include <cstring>
  14. #include <fstream>
  15. #include <iomanip>
  16. #include <numeric>
  17. #include <sstream>
  18. #include <utility>
  19. #include <iostream>
  20. #include <algorithm>
  21.  
  22. using namespace std;
  23.  
  24. class AliceGameEasy {
  25. public:
  26. long long findMinimumValue( long long x, long long y )
  27. {
  28. long long sum = x + y;
  29. long long root = (long long) sqrt(1 + 8 * sum);
  30.  
  31. if(root * root != 1 + 8 * sum)
  32. return -1;
  33.  
  34. long long round = (-1 + root) / 2;
  35. long long sol = 0;
  36. long long s = 0;
  37.  
  38. if(round == 0 || x == 0)
  39. return 0;
  40.  
  41. for(int i=round;i>=1;i--)
  42. {
  43. if(s + i >= x)
  44. return sol + 1;
  45. else
  46. {
  47. s += i;
  48. sol ++;
  49. }
  50. }
  51. return -1;
  52. }
  53. };
  54.  
  55. int main()
  56. {
  57. AliceGameEasy obj;
  58. cout << obj.findMinimumValue( 0, 1) << endl;
  59. return 0;
  60. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
0