1 class Solution 2 { 3 public: 4 int shipWithinDays(vector<int>& weights, int D) 5 { 6 int load = 0; 7 for(int i = 0; i< weights.size();i ++) 8 { 9 load += weights[i]; 10 } 11 int rnt = load/D-1; 12 while(1) 13 { 14 int i = 0; 15 int tmpD = D; 16 while(tmpD && i < weights.size()) 17 { 18 int tmp = rnt; 19 while(i < weights.size() && tmp-weights[i]>=0) 20 { 21 tmp -= weights[i]; 22 i ++; 23 } 24 if(i >= weights.size()) 25 break; 26 tmpD --; 27 } 28 if(i>=weights.size()) 29 break; 30 rnt ++; 31 } 32 return rnt; 33 } 34 };