Question:
Solution:
1. take all the necessary inputs.
2. let count be the variable of the counter. you have to check so that count<P and count<N,then add the weight and recheck. Pseudo code is given below:
#include<stdio.h>
int main(){
while(T--){
int main(){
while(T--){
.......
.......
for(W=count=0; count<P && count<N;){
if(W+a[count]>Q)
break;
W+=a[count++];
}
printf("Case %d: %d\n", c++, count);
}
return 0;
}
for(W=count=0; count<P && count<N;){
if(W+a[count]>Q)
break;
W+=a[count++];
}
printf("Case %d: %d\n", c++, count);
}
return 0;
}