G. Transport treasures time limit:1000 MS case time limit:1000 Ms Memory limit:64 MB
Total submission:53 submission Accepted:22description is known to all, "watermelon" is the famous thief. Once he stole a treasure trove.
There are N of these treasures, he has a total of k boxes. He can only use these boxes to carry these treasures out, in order to ensure the safety of transport, he will not put more than two treasures in the same box (a box can only be loaded with 1 or 2 treasures). The sizes of these treasures are S (1), S (2), S (3) ... s (n), respectively. (The weight guarantee given by the title is non-descending, i.e. S (i-1) <=s (i) for any i>1).
After the treasures are loaded, each box has a capacity greater than or equal to the sum of the size of the treasures installed. For uniform specifications, each of these boxes has a consistent capacity. In order to reduce freight, the capacity of the box should be as small as possible. "Watermelon" want to know, in the case can be transported away, the size of the box is the smallest.
Input multiple sets of inputs
First enter N and K (1≤n≤2 k≤100), n is the number of treasures, K is the number of boxes.
The next line enters a space-delimited n integer, s1,s2,..., sn (1≤s1≤s2≤ ... ≤sn≤1 000 000), representing the weight of these treasures.
Output outputs an integer that represents the minimum value of the capacity of these boxes.
Sample Input
4 32 3) 5 9
Sample Output
9
Just pack the treasures from the big to the small, and then put the rest of the treasures in small to large boxes from the largest to the smallest.
Finally, find out the maximum value of all chests
1#include <cstdio>2#include <string>3#include <cstring>4#include <cmath>5#include <memory>6#include <stack>7#include <queue>8#include <Set>9#include <algorithm>Ten#include <map> One#include <vector> A using namespacestd; - - #defineDebug 0 the - /* - By:ohyee - Github:ohyee + Email:[email protected] - Blog:http://www.cnblogs.com/ohyee/ + A かしこいかわいい? at エリーチカ! - to write out the хорошо code OH ~ - */ - #defineREP (n) for (int o=0;o<n;o++) - Const intmaxn=100005; - Const intmaxk=50005; in - intn,k; to intS[MAXN]; + - BOOLDo () { the if(SCANF ("%d%d", &n,&k) = =EOF) * return false; $ REP (n)Panax Notoginsengscanf"%d",&S[o]); - the if(k>=N) { +printf"%d\n", s[n-1]); A return true; the } + - intW[MAXK]; $ REP (k) { $w[o]=s[n-k+O]; - } - the #ifDebug - REP (n)Wuyiprintf"s[%d]=%d\n", O,s[o]); theprintf"\ n"); - REP (k) Wuprintf"w[%d]=%d\n", O,w[o]); -printf"\ n"); About #endif //Debug $ - for(intI=0; i<n-k;i++){ -w[i]+=s[n-k-1-i]; - } A + the - intm=w[0]; $ REP (k) { them=Max (M,w[o]); the } the #ifDebug the REP (k) -printf"w[%d]=%d\n", O,w[o]); in #endif //Debug theprintf"%d\n", M); the About return true; the the } the + - the intMain () {Bayi #ifDebug theFreopen ("In.txt","R", stdin); the #endif - while(Do ()); - return 0; the}
AOJ 802. Transporting Treasures