1606: [usaco DEC] hay for sale hay purchase time limit: 5 sec memory limit: 64 MB
Submit: 612 solved: 463
[Submit] [Status] Description John suffered a major loss: cockroaches ate all his hay, leaving a group of ELE. Me cows. he took a carriage with a capacity of C (1 ≤ C ≤ 50000) and went to the house to buy some hay. because of the hay package of H (1 ≤ h ≤ 5000), each package has its volume VI (L ≤ VI ≤ C ). john can only buy the whole package. How much hay can he transport at most? Input 1st rows input C and h, and then H rows input a line VI. Output maximum purchased hay volume. Sample input7 3 // total volume is 7, use 3 items to carry a backpack
2
6
5
The wagon holds 7 volumetric units; three bales are offered for sale
Volumes of 2, 6, and 5 units, respectively.
Sample output7 // maximum size that can be backed up
Hint
Buying the two smaller bales fills the wagon.
Source
Silver
Question: Determining backpack... Are you still taking this test in the U.S. in? Code:
1 var 2 i,j,m,x,n:longint; 3 f:array[0..100000]of boolean; 4 begin 5 assign(input,‘input.txt‘);assign(output,‘output.txt‘); 6 reset(input);rewrite(output); 7 readln(m,n); 8 f[0]:=true; 9 for i:=1 to n do10 begin11 readln(x);12 for j:=m downto x do13 f[j]:=f[j] or (f[j-x]);14 end;15 for i:=m downto 0 do if f[i] then break;16 writeln(i);17 close(input);close(output);18 end.19
View code