Untitled

 avatar
unknown
plain_text
3 months ago
1.1 kB
7
Indexable
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n , x ;
    cin >> n >>x ;
   vector<ll>v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i] ;
       // v[i].second = i+1;
    }
    sort(v.begin(),v.end());

    vector<pair<ll,ll>>prifx(n+1);
    prifx[0].first = 0;
    prifx[0].second = 0;
    for (int i = 1; i <= n; i++) {
        prifx[i].first = prifx[i-1].first + v[i-1];
        prifx[i].second = i;
    }
  //  for (int i = 0; i <= n; i++) {
  //  cout << prifx[i].first << " " << prifx[i].second << "\n";
   // }

    ll l = 1 , r = n ;
    while (l <= r) {
        if (prifx[r].first - prifx[l-1].first <= x) {
            cout << prifx[r].second - prifx[l-1].second << "\n";
            break;
        }
        else {
            r--;
        }
    }
    if (l > r) {
        cout << 0 << "\n";
    }

}
Editor is loading...
Leave a Comment