#include using namespace std; typedef long long ll; #define rep(i,n) for(i=0;i>n >>m; //本来の値とどれくらい離れているか ll d=a[n]-m; int ans=0; ll now=n-2; while(now>0 || d>0){ if(d-a[now]>=0){ d-=a[now]; ++ans; } --now; } if(d!=0) ans=-1; std::cout << ans << std::endl; return 0; }