3 solutions

  • 1
    @ 2026-8-14 15:58:31
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n,m;
    	cin>>n>>m;
    	int cnt=0;
    	for(int i=1;i<=n;i++)
    	{
    		int h;
    		cin>>h;
            if(m>=h)
    		{
    			m=m-h;
    			cnt++;
    		}
    		else
    		{
                break;
    		}
    	}
    	cout<<cnt;
    	return 0; 
    }
    
    • 0
      @ 2026-8-20 20:26:02
      #include<bits/stdc++.h>
      using namespace std;
      int main()
      {
          int n,m;
          cin>>n>>m;
          int s=0,c=0;
          for(int i=1;i<=n;i++)
          {
              int x;
              cin>>x;
              if(s+x<=m)//判断如果一瓶消毒剂没有外星人的手
              {
                  s+=x;
                  c++;
              }
              else
              {
                  break;
                 // return 0;
              }
          }
          cout<<c;
      	return 0;
      }
      
      • 0
        @ 2026-1-17 10:11:09
        #include<bits/stdc++.h>
        using namespace std;
        int main()
        {
        	int n,m;
        	cin>>n>>m;
        	int s=0,cnt=0;
        	for(int i=1;i<=n;i++) 
        	{
        		int x;
        		cin>>x;
        		if(x+s<=m)
        		{
        			s+=x; 
        			cnt++;
        		}
        		else
        		{
        			break;
        		}
        	}
        	cout<<cnt;
            return 0;
        }
        
        
        • 1

        Information

        ID
        2347
        Time
        1000ms
        Memory
        256MiB
        Difficulty
        1
        Tags
        (None)
        # Submissions
        147
        Accepted
        52
        Uploaded By