CPP   116
LUYENTAP
Guest on 21st February 2022 12:19:08 PM


  1. // de 12 (2018-2019) DONG THAP
  2. #include<bits/stdc++.h>
  3. using namespace std ;
  4.  
  5. int n,a[1000000];
  6. long long k,res=0,ngay = 0,MIN = 51000 ;
  7.  
  8. int main()
  9. {
  10.     cin >> n  >> k;
  11.  
  12.     for (int i=1 ; i<=n ; i++)
  13.         cin >> a[i];
  14.  
  15.  
  16.     for(int i=1 ; i<=n ; i++)
  17.     {
  18.        int x = i;
  19.        while(res <= k)
  20.         {
  21.         res = res + a[x];
  22.         x++;
  23.         ngay++;
  24.         }
  25.         if ((ngay < MIN) and (ngay!=0) and (ngay!=1))
  26.         {
  27.             MIN = ngay;
  28.  
  29.         }
  30.         ngay = 0;
  31.         res = 0 ;
  32.     }
  33.  
  34.     if(MIN!=51000)
  35.         cout << MIN ;
  36.     else cout << -1;
  37.  
  38.     return 0;
  39. }

Raw Paste

Login or Register to edit or fork this paste. It's free.