Advertisement
theo830

CODE

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