Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
332 B
0
Indexable
Never
#include <iostream>
#include<math.h>
using  namespace std;
int main()
{
    int n,a[100];
    cin>>n;
    int m;
    cin>>m;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int k=0;int g;
    for(int i=0;i<n;i++)
    {
        if(k+a[i]<=m)
        {
            k=k+a[i];
            g++;
        }
    }
    cout<<g;
}