{"id":"909a0073-0a87-479f-9c4a-fda766c3f0e3","name":"Capacity To Ship Packages Within D Days","description":"1. A conveyor belt has packages that must be shipped from one port to another within D days.\r\n2. The ith package on the conveyor belt has a weight of weights[i]. Each day, we load the ship with packages on the conveyor belt (in the order given by weights). We may not load more weight than the maximum weight capacity of the ship.\r\n3. Return the least weight capacity of the ship that will result in all the packages on the conveyor belt being shipped within D days.\r\n","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1 &lt;= days &lt;= weights.length &lt;= 5 * 10^4\r\n1 &lt;= weights[i] &lt;= 500","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nint shipWithinDays(vector<int>& wt, int days){\n //Write your code here\n}\n\nint main(){\n int n;\n cin>>n;\n vector<int> wt(n,0);\n for(int i=0; i<n; i++){\n cin>>wt[i];\n }\n int days;\n cin>>days;\n\n int ans = shipWithinDays(wt, days);\n cout<<ans<<endl;\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static int shipWithinDays(int[]arr, int days) {\r\n //write your code here\r\n return 0;\r\n }\r\n\r\n public static void main(String[]args) {\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n\r\n int[]arr = new int[n];\r\n\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n int days = scn.nextInt();\r\n\r\n int ans = shipWithinDays(arr, days);\r\n System.out.println(ans);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"10\r\n2 3 4 1 5 6 7 9 8 10\r\n5","sampleOutput":"15","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"40a9acdc-74f3-40e6-ac2a-48e9ba82d673","name":"Capacity To Ship Packages Within D Days","slug":"capacity-to-ship-packages-within-d-days","type":1}],"next":{"id":"c87eb627-99d9-4093-b283-94b0b86b1554","name":"Capacity to ship packages within d days","type":3,"slug":"capacity-to-ship-packages-within-d-days"},"prev":{"id":"3eff3bec-defc-4e65-9511-c4e0111df989","name":"Count The Triplets MCQ","type":0,"slug":"count-the-triplets-mcq"}}}

Capacity To Ship Packages Within D Days

1. A conveyor belt has packages that must be shipped from one port to another within D days. 2. The ith package on the conveyor belt has a weight of weights[i]. Each day, we load the ship with packages on the conveyor belt (in the order given by weights). We may not load more weight than the maximum weight capacity of the ship. 3. Return the least weight capacity of the ship that will result in all the packages on the conveyor belt being shipped within D days.

{"id":"909a0073-0a87-479f-9c4a-fda766c3f0e3","name":"Capacity To Ship Packages Within D Days","description":"1. A conveyor belt has packages that must be shipped from one port to another within D days.\r\n2. The ith package on the conveyor belt has a weight of weights[i]. Each day, we load the ship with packages on the conveyor belt (in the order given by weights). We may not load more weight than the maximum weight capacity of the ship.\r\n3. Return the least weight capacity of the ship that will result in all the packages on the conveyor belt being shipped within D days.\r\n","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1 &lt;= days &lt;= weights.length &lt;= 5 * 10^4\r\n1 &lt;= weights[i] &lt;= 500","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nint shipWithinDays(vector<int>& wt, int days){\n //Write your code here\n}\n\nint main(){\n int n;\n cin>>n;\n vector<int> wt(n,0);\n for(int i=0; i<n; i++){\n cin>>wt[i];\n }\n int days;\n cin>>days;\n\n int ans = shipWithinDays(wt, days);\n cout<<ans<<endl;\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static int shipWithinDays(int[]arr, int days) {\r\n //write your code here\r\n return 0;\r\n }\r\n\r\n public static void main(String[]args) {\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n\r\n int[]arr = new int[n];\r\n\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n int days = scn.nextInt();\r\n\r\n int ans = shipWithinDays(arr, days);\r\n System.out.println(ans);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"10\r\n2 3 4 1 5 6 7 9 8 10\r\n5","sampleOutput":"15","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"40a9acdc-74f3-40e6-ac2a-48e9ba82d673","name":"Capacity To Ship Packages Within D Days","slug":"capacity-to-ship-packages-within-d-days","type":1}],"next":{"id":"c87eb627-99d9-4093-b283-94b0b86b1554","name":"Capacity to ship packages within d days","type":3,"slug":"capacity-to-ship-packages-within-d-days"},"prev":{"id":"3eff3bec-defc-4e65-9511-c4e0111df989","name":"Count The Triplets MCQ","type":0,"slug":"count-the-triplets-mcq"}}}
plane

Editor


Loading...

Capacity To Ship Packages Within D Days

medium

1. A conveyor belt has packages that must be shipped from one port to another within D days. 2. The ith package on the conveyor belt has a weight of weights[i]. Each day, we load the ship with packages on the conveyor belt (in the order given by weights). We may not load more weight than the maximum weight capacity of the ship. 3. Return the least weight capacity of the ship that will result in all the packages on the conveyor belt being shipped within D days.

Constraints

1 <= days <= weights.length <= 5 * 10^4 1 <= weights[i] <= 500

Format

Input

Input is managed for you

Output

Output is managed for you

Example

Sample Input

10 2 3 4 1 5 6 7 9 8 10 5

Sample Output

15

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode