Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <random>
- #include <cstdlib>
- #include <cassert>
- #include <algorithm>
- #include <cmath>
- using namespace std;
- #define int long long
- mt19937 rnd(12345);
- const int N = 2e5 + 7;
- const unsigned int MOD = 1e9 + 7;
- int n, a[N], cnt, x, r;
- unsigned long long ans, prefixsum[N];
- void solve() {
- ans = 0;
- cin >> n >> x;
- for (int i = 0; i < n; i++) {
- cin >> a[i];
- }
- sort(a, a + n);
- if (a[0] > x) {
- cout << "0\n";
- return;
- }
- int delta = 0, last_delta = -1;
- prefixsum[0] = a[0];
- for (int i = 1; i < n; i++) {
- prefixsum[i] = prefixsum[i - 1] + a[i];
- }
- int r = 0;
- while (prefixsum[r + 1] <= x && r < n-1) {
- r++;
- }
- for (r; r >= 0; r--) {
- int y = (x - prefixsum[r]) / (r + 1);
- ans += (r + 1) * (y - last_delta);
- last_delta = y;
- }
- cout << ans << '\n';
- }
- signed main()
- {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- #else
- ios::sync_with_stdio(false);
- cin.tie(0);
- #endif
- int t;
- cin >> t;
- while (t--) {
- solve();
- }
- //cin >> n;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement