• + 1 comment

    The editorial optimization 3 is wrong and bad way . The optimization 4 is good approach . Suppose u have 0 1 coins , 3 2 coins ,2 5 coins , 1 10 coins. Then U can't make N if(13) But as rule of optimization of 3

    (2*i+5*j+10*k>=(N-A)) count++;

    many times 2*i+5*j+10*k this part will be greater than (13-0) . So what rubbish solution that is !!!

    include

    using namespace std;

    int main() { int T,N,A,B,C,D; cin>>T; while(T--) { cin>>N; cin>>A>>B>>C>>D; long long ways[N+1]={0}; for(int i=0;i<=A;i++) { for(int j=0;j<=B&&(i+2*j)<=N;j++) { ways[(i+2*j)]++; } } long long ans=0; for(int i=0;i<=C&&(i*5)<=N;i++) { for(int j=0;j<=D&&((i*5)+(10*j))<=N;j++) { ans+=ways[N-((i*5)+(10*j))]; } } cout<