Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. //#pragma GCC optimize("O3")
  3. #define count masloriy1489
  4. #define y1 jhgfds
  5. #define ll long long
  6. #define pb push_back
  7. #define eb emplace_back
  8. #define all(v) v.begin(), v.end()
  9. #define rep(i, n) for(ll i = 0; i < n; i++)
  10.  
  11. using namespace std;
  12. //freopen("input.txt", "r", stdin);
  13. //freopen("output.txt", "w", stdout);
  14.  
  15. int main(){
  16. ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  17. #define int long long
  18. int n, m;
  19. cin >> n >> m;
  20. vector<int> a(n);
  21. int sum = 0;
  22. rep(i, n){
  23. cin >> a[i];
  24. sum += a[i];
  25. }
  26. if(sum < m){
  27. cout << -1;
  28. return 0;
  29. }
  30. sort(all(a));
  31. int l = 1, r = n;
  32. while(r - l > 1){
  33. int c = (l + r)>>1;
  34. vector<int> b(a);
  35. int now = m;
  36. int diff = 0;
  37. while(!b.empty() && now > 0){
  38. rep(i, c){
  39. if(b.empty())
  40. break;
  41. now = now - (b.back()-diff);
  42. b.pop_back();
  43. }
  44. diff++;
  45. }
  46. if(now <= 0)
  47. r = c;
  48. else
  49. l = c;
  50. }
  51. int c = l;
  52. vector<int> b(a);
  53. int now = m;
  54. int diff = 0;
  55. while(!b.empty() && now > 0){
  56. rep(i, c){
  57. if(b.empty())
  58. break;
  59. now -= (b.back()-diff);
  60. b.pop_back();
  61. }
  62. diff++;
  63. }
  64. if(now <= 0)
  65. c = l;
  66. else
  67. c = r;
  68. cout << c;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement