Advertisement
theo830

code

May 25th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. if(w == T[n][w]){
  2. for (i = n; i > 0 && res > 0; i--) {
  3. if (res == T[i - 1][w])
  4. continue;
  5. else {
  6. o++;
  7. res = res - wt[i - 1];
  8. w = w - wt[i - 1];
  9. }
  10. if(w == 0){
  11. break;
  12. }
  13. }
  14. int curr_sum = wt[0], start = 0;
  15. for (i = 1; i <= n; i++)
  16. {
  17. while (curr_sum > res && start < i-1)
  18. {
  19. curr_sum = curr_sum - wt[start];
  20. start++;
  21. if(curr_sum == 0){
  22. o = min(o,i - start);
  23. }
  24. }
  25.  
  26. if (i < n)
  27. curr_sum = curr_sum + wt[i];
  28. }
  29.  
  30. return o;
  31. }
  32. else{
  33. return -1;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement