fork(6) download
  1. /**
  2.  * code generated by JHelper
  3.  * More info: https://g...content-available-to-author-only...b.com/AlexeyDmitriev/JHelper
  4.  * @author gainullin.ildar
  5.  */
  6.  
  7. #include <iostream>
  8. #include <vector>
  9. #include <algorithm>
  10. #include <string>
  11. #include <set>
  12. #include <map>
  13. #include <list>
  14. #include <time.h>
  15. #include <math.h>
  16. #include <random>
  17. #include <deque>
  18. #include <queue>
  19. #include <cassert>
  20.  
  21. using namespace std;
  22.  
  23. typedef long long ll;
  24.  
  25. const int N = 1e5 + 7;
  26.  
  27. int n, S;
  28. int a[N];
  29. ll b[N];
  30.  
  31. ll res(int k)
  32. {
  33. for (int i = 0; i < n; i++)
  34. {
  35. b[i] = a[i] + (i + 1) * (ll) k;
  36. }
  37. sort(b, b + n);
  38. ll ans = 0;
  39. for (int i = 0; i < k; i++)
  40. {
  41. ans += b[i];
  42. }
  43. return ans;
  44. }
  45.  
  46. class Main
  47. {
  48. public:
  49. void solve(std::istream &in, std::ostream &out)
  50. {
  51. in >> n >> S;
  52. for (int i = 0; i < n; i++)
  53. {
  54. in >> a[i];
  55. }
  56. int l = 0, r = n + 1;
  57. while (l < r - 1)
  58. {
  59. int m = (l + r) / 2;
  60. if (res(m) <= S)
  61. {
  62. l = m;
  63. }
  64. else
  65. {
  66. r = m;
  67. }
  68. }
  69. out << l << ' ' << res(l) << '\n';
  70. }
  71. };
  72.  
  73.  
  74. int main()
  75. {
  76. ios::sync_with_stdio(0);
  77. Main solver;
  78. std::istream &in(std::cin);
  79. std::ostream &out(std::cout);
  80. solver.solve(in, out);
  81. return 0;
  82. }
  83.  
Success #stdin #stdout 0s 16400KB
stdin
Standard input is empty
stdout
0 0