Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(w == T[n][w]){
- for (i = n; i > 0 && res > 0; i--) {
- if (res == T[i - 1][w])
- continue;
- else {
- o++;
- res = res - wt[i - 1];
- w = w - wt[i - 1];
- }
- if(w == 0){
- break;
- }
- }
- int curr_sum = wt[0], start = 0;
- for (i = 1; i <= n; i++)
- {
- while (curr_sum > res && start < i-1)
- {
- curr_sum = curr_sum - wt[start];
- start++;
- if(curr_sum == 0){
- o = min(o,i - start);
- }
- }
- if (i < n)
- curr_sum = curr_sum + wt[i];
- }
- return o;
- }
- else{
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement