fork download
  1. /* g++ -O2 -std=c++11 */
  2.  
  3. /* input/output streams and formatting */
  4. #include <iostream>
  5. #include <cstdio>
  6. #include <sstream>
  7. #include <iomanip>
  8.  
  9. /* data structures */
  10. #include <vector>
  11. #include <map>
  12. #include <stack>
  13. #include <queue>
  14. #include <deque>
  15. #include <set>
  16. #include <bitset>
  17. #include <unordered_map>
  18.  
  19. /* useful libs */
  20. #include <cstring>
  21. #include <cstdlib>
  22. #include <algorithm>
  23. #include <cmath>
  24. #ifdef LOCAL_DEBUG
  25. #include <ctime>
  26. #endif
  27.  
  28. /* don't use this shit in your projects,
  29.  * it's only useful in olympiads !
  30.  */
  31. using namespace std;
  32.  
  33. /* some useful defines */
  34. #define fi first
  35. #define se second
  36. #define pb(x) push_back(x)
  37. #define ppb(x) pop_back(x)
  38. #define mp(x, y) make_pair((x), (y))
  39. #define all(a) (a).begin(), (a).end()
  40. #define rall(a) (a).rbegin(), (a).rend()
  41. #define forn(i, n) for(int i=0; i<(n); i++)
  42. #define for1(i, n) for(int i=1; i<=(n); i++)
  43. #define forr(i, n) for(int i=(n); i-->0; )
  44. #define forab(i, a, b) for (int i=(int)(a); i<(int)(b); i++)
  45.  
  46. /* commonly used types */
  47. typedef pair<int, int> pii;
  48. typedef vector<int> vi;
  49. typedef vector<pii> vpi;
  50. typedef vector<vi> vvi;
  51. typedef long long i64;
  52. typedef vector<i64> vi64;
  53. typedef vector<vi64> vv64;
  54. typedef pair<i64, i64> pi64;
  55.  
  56. /* geometric types */
  57. template <typename T> struct point2d { T x; T y; };
  58. template <typename T> struct line2d { T a; T b; T c; };
  59. template <typename T> struct circle2d { point2d<T> c; T r; };
  60. typedef point2d<int> p2i;
  61. typedef point2d<double> p2f;
  62. typedef line2d<int> l2i;
  63. typedef line2d<double> l2f;
  64. typedef circle2d<int> c2i;
  65. typedef circle2d<double> c2f;
  66.  
  67.  
  68. #define su(m) ((m)*((m)+1))/2
  69. i64 find(i64 a, i64 b, i64 k){
  70. i64 m = (a + b)/(i64)2;
  71. if (su(m) < k && su(m+1) >= k)
  72. return m;
  73. if (su(m) > k)
  74. return find(a, m, k);
  75. else
  76. return find(m+1, b, k);
  77. }
  78.  
  79.  
  80. int a;
  81. int main()
  82. {
  83. // input/output manipulation
  84. ios::sync_with_stdio(false);
  85. cout.precision(10);
  86. cout << fixed;
  87.  
  88. // write the solution here
  89.  
  90. i64 n, k;
  91. scanf("%ld%ld", &n, &k);
  92.  
  93. cout << n << " " << k << endl;
  94. exit(0);
  95.  
  96. i64 m = std::sqrt(k);
  97. if (su(m-1) < k && su(m) >= k)
  98. m = m-1;
  99. if (su(m) < k && su(m+1) >= k)
  100. m = m;
  101. if (su(m+1) < k && su(m+2) >= k)
  102. m = m+1;
  103. // n*(n+1)/2 <= k;
  104. // n(n+1) <= 2k
  105. //i64 m = find(0, k, k);
  106. int l = k - su(m) - 1;
  107. forn(i, n){
  108. scanf("%d", &a);
  109. if (i == l){
  110. printf("%d\n", a);
  111. break;;
  112. }
  113. }
  114.  
  115.  
  116. #ifdef LOCAL_DEBUG
  117. cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
  118. #endif
  119. return 0;
  120. }
Success #stdin #stdout 0s 3460KB
stdin
2 2
1 2
stdout
-5225681348924014590 577738187246403586