DingleBells / USACO

0 stars 0 forks source link

Milk Mixing #11

Open DingleBells opened 3 years ago

DingleBells commented 3 years ago

The Merry Milk Makers company buys milk from farmers, packages it into attractive 1- and 2-Unit bottles, and then sells that milk to grocery stores so we can each start our day with delicious cereal and milk.

Since milk packaging is such a difficult business in which to make money, it is important to keep the costs as low as possible. Help Merry Milk Makers purchase the farmers' milk in the cheapest possible manner. The MMM company has an extraordinarily talented marketing department and knows precisely how much milk they need each day to package for their customers.

The company has contracts with several farmers from whom they may purchase milk, and each farmer has a (potentially) different price at which they sell milk to the packing plant. Of course, a herd of cows can only produce so much milk each day, so the farmers already know how much milk they will have available.

Each day, Merry Milk Makers can purchase an integer number of units of milk from each farmer, a number that is always less than or equal to the farmer's limit (and might be the entire production from that farmer, none of the production, or any integer in between).

Given:

The Merry Milk Makers' daily requirement of milk The cost per unit for milk from each farmer The amount of milk available from each farmer calculate the minimum amount of money that Merry Milk Makers must spend to meet their daily need for milk. Note: The total milk produced per day by the farmers will always be sufficient to meet the demands of the Merry Milk Makers even if the prices are high.

Line 1: Two integers, N and M.The first value, N, (0 <= N <= 2,000,000) is the amount of milk that Merry Milk Makers wants per day. The second, M, (0 <= M <= 5,000) is the number of farmers that they may buy from.
Lines 2 through M+1: The next M lines each contain two integers: Pi and Ai.Pi (0 <= Pi <= 1,000) is price in cents that farmer i charges.Ai (0 <= Ai <= 2,000,000) is the amount of milk that farmer i can sell to Merry Milk Makers per day.

SAMPLE INPUT (file milk.in) 100 5 5 20 9 40 3 10 8 80 6 30 INPUT EXPLANATION 100 5 -- MMM wants 100 units of milk from 5 farmers 5 20 -- Farmer 1 says, "I can sell you 20 units at 5 cents per unit" 9 40 etc. 3 10 -- Farmer 3 says, "I can sell you 10 units at 3 cents per unit" 8 80 etc. 6 30 -- Farmer 5 says, "I can sell you 30 units at 6 cents per unit" OUTPUT FORMAT A single line with a single integer that is the minimum cost that Merry Milk Makers must pay for one day's milk.

SAMPLE OUTPUT (file milk.out) 630

Output Explaination: Price per unit Units available Unitsbought Price *# units Total cost Notes
5 20 20 5*20 100
9 40 0     Bought no milk from farmer 2
3 10 10 3*10 30
8 80 40 8*40 320 Did not buy all 80 units!
6 30 30 6*30 180
Total 180 100   630 Cheapest total cost
DingleBells commented 3 years ago

100000 1000 183 4065 865 6383 78 179 93 9827 736 5969 437 6413 546 959 630 3332 115 1024 700 1408 740 2997 921 3853 144 5586 554 467 6 7698 900 5940 804 8030 898 6022 621 2376 274 2354 390 8878 592 4366 934 8076 546 4839 612 785 686 2817 269 2341 210 2595 637 7930 346 2909

DingleBells commented 3 years ago

100000 1000 183 4065 865 6383 78 179 93 9827 736 5969 437 6413 546 959 630 3332 115 1024 700 1408 740 2997 921 3853 144 5586 554 467 6 7698 900 5940 804 8030 898 6022 621 2376 274 2354 390 8878 592 4366 934 8076 546 4839 612 785 686 2817 269 2341 210 2595 637 7930 346 2909 797 2466 638 6332 79 3120 36 4049 638 5827 796 8781 376 6447 35 4896 840 9180 394 2467 599 3972 183 1379 451 7192 859 736 555 5650 518 4565 761 9297 240 4169 784 4977 681 2407 184 1515 275 8730 559 5724 814 268 538 872 492 3759 677 1921 389 4252 815 4339 326 459 41 3411 230 4835 952 3144 480 1476 880 7865 64 4545 955 9272 79 8642 131 8990 273 7018 636 5831 305 5221 237 128 570 1173 992 1120 817 7998 264 5571 10 4623 66 6109 352 5395 423 4046 16 2647 521 8402 256 2845 3 7147 588 3186 918 4514 817 1867 696 3786 125 2310 23 2645 526 3007 183 7885 218 9105 513 2539 295 2654 188 4410 435 401 927 5361 70 5251 880 6334 535 8315 110 7919 692 7674 958 550 982 9335 356 2877 324 1959 15 5798 814 6656 266 2855 429 7871 744 2308 584 231 24 6078 770 3195 257 1308 258 2382 511 360 811 3434 254 6700 437 2655 846 781 531 1982 0 4456 54 9925 247 795 394 3548 682 8021 791 528 370 8097 50 831 655 4831 893 2403 127 4997 732 2291 305 981 850 6952 454 1407 219 9788 401 3162 794 7528 16 5102 973 4542 387 452 216 6725 397 3968 56 197 313 5518 784 6898 839 9996 305 813 622 6296 949 2872 851 347 372 2744 274 916 259 9585 773 3368 241 8061 499 2041 851 7454 946 2325 914 1222 568 7218 500 355 934 4071 752 5151 974 5245 758 2568 46 2039 726 7804 164 8111 967 4952 893 9265 179 6433 913 2780 56 5619 265 5111 666 649 475 7938 279 3230 572 7550 819 3810 152 7357 437 4159 990 397 465 9806 407 370 807 6756 624 5938 220 2642 318 8966 255 92 473 2047 406 5880 651 2614 891 3018 91 231 928 3182 509 6319 442 39 276 3716 221 5943 899 4709 964 1326 855 915 548 6487 193 9982 937 4016 867 1700 72 9433 200 342 238 3184 233 6300 721 7547 884 5515 830 1334 367 8069 610 1295 718 608 756 6495 418 6730 27 8425 507 7677 724 6504 382 4878 423 3414 785 5451 986 5928 846 4948 821 5233 374 8026 487 5142 673 7302 929 525 579 6172 801 4364 712 2001 738 8497 251 3593 537 5405 827 6773 595 581 559 3660 469 7722 723 8680 532 3527 635 8323 134 2829 935 4113 224 6187 376 4736 314 240 386 3119 743 4628 746 668 129 69 185 2050 244 3278 465 385 321 1006 295 543 142 999 346 574 324 4499 611 1742 225 8719 565 3797 343 3698 655 5325 787 9869 31 7070 386 4120 617 9756 938 1739 240 2435 5 6955 99 5201 619 2407 444 1411 976 6226 29 1204 106 5378 395 7778 535 281 680 1634 599 9619 171 6821 494 1616 618 1179 997 1315 107 4617 817 8250 151 4022 915 6560 888 3323 73 1120 388 9595 565 6844 370 799 372 9806 492 5606 353 4397 22 1947 700 883 862 3688 421 9709 851 7595 653 6307 34 5527 198 2921 663 9565 665 2727 833 7323 208 612 481 8372 629 8057 300 4113 443 2612 463 5864 387 1754 426 730 194 2514 976 4498 9 4046 509 475 852 8844 544 6482 167 8861 380 5341 93 4836 49 1242 986 2322 184 2876 476 5024 631 8914 5 2797 800 761 516 2138 545 8149 909 5891 511 5706 941 1263 796 8416 826 1611 452 5144 27 7250 650 8776 419 8624 631 9854 508 4745 221 3907 833 1316 576 1086 499 7180 414 2764 49 6697 617 8605 282 9467 243 3873 724 6264 113 1540 265 6247 114 5575 736 1725 538 9087 810 2774 650 5042 751 3351 289 4016 776 3058 697 7791 885 3898 507 2635 833 632 196 5517 4 9614 836 5418 281 2571 836 7629 346 655 672 696 104 5233 661 6216 703 6445 348 3479 657 306 991 8535 241 2588 36 6268 611 2590 296 8475 178 7187 733 2672 226 3782 926 628 487 4879 978 9808 861 7824 719 8252 233 6879 569 5644 440 117 459 8300 542 7672 4 9593 241 7221 134 9267 822 8784 323 8049 236 6400 57 4420 464 6437 39 399 233 9676 615 8902 717 9669 175 2758 331 7731 51 9012 506 4485 781 4937 401 9828 399 4109 880 7405 767 1298 663 992 692 4083 486 5033 848 4222 820 6733 631 2846 131 4103 262 5917 292 4580 439 7833 222 5405 676 6244 685 2532 730 1681 824 322 864 3789 75 8783 16 3323 751 178 269 9108 206 58 68 4461 747 2669 336 5689 265 1680 624 3314 611 1542 412 2467 132 5341 96 6520 31 775 591 9129 489 581 540 5540 365 9049 573 7897 192 4141 24 9514 742 4894 842 4259 572 2398 94 3703 423 7210 578 5869 765 8919 952 8394 403 9043 796 2543 599 2314 497 1060 262 1398 208 5046 24 7516 851 9006 818 740 799 4354 356 5223 592 4177 244 6527 177 4794 826 746 83 6765 981 5839 734 1493 390 565 678 2677 908 177 727 2785 399 9376 692 2559 512 7205 932 9247 601 9299 959 4071 489 1277 615 8131 234 6189 457 9723 334 6147 69 7830 991 1504 900 9038 437 4306 626 1125 766 8497 180 5031 497 26 844 5521 115 586 986 5185 173 5822 172 5310 429 2970 905 7819 932 3687 338 103 512 6417 235 9560 979 2512 504 1687 483 7079 507 2670 739 906 773 7536 82 8468 258 3480 146 4952 305 9078 995 9463 980 8534 777 3683 21 6786 515 4481 778 9514 101 1189 138 8337 896 4137 888 1418 808 3055 135 1268 206 6376 918 1843 87 7733 342 2720 268 861 257 3507 468 94 702 286 310 1688 417 9404 595 9303 712 3786 331 3808 27 4149 871 3951 987 4934 335 1167 63 90 508 9195 322 2838 264 243 873 9610 972 8385 603 2931 123 222 66 1126 693 3487 281 1290 30 884 957 663 623 1507 257 5597 605 2050 653 7734 521 5875 86 9343 519 1347 451 9571 555 4452 431 3754 160 9082 123 6273 387 7413 309 4650 216 2509 662 7686 666 3443 280 865 832 582 831 8446 534 8580 185 5459 946 1955 408 1351 848 9535 920 3402 847 9621 780 3364 805 3488 901 3745 864 2643 453 8876 663 679 337 6123 744 3446 837 2826 859 8552 580 2187 743 508 416 9837 779 9770 54 3067 55 6616 790 615 603 90 337 9000 328 1438 899 4816 110 5639 811 5602 126 5209 632 6707 336 1301 335 6606 23 566 706 1309 412 8332 154 4486 872 4424 856 403 109 2633 768 5845 247 5861 360 8555 567 6714 727 4078 368 2790 736 9008 173 9380 689 6340 883 809 463 4512 107 9903 484 2706 602 2528 779 9263 644 4198 755 4098 173 769 683 8996 730 2105 285 4103 920 5462 157 9417 643 237 290 9558 633 2269 734 2349 824 2361 411 3319 229 2759 847 8963 430 3209 266 8583 410 8906 508 5811 823 4908 324 7078 140 3153 461 6246 616 1128 660 507 267 8329 288 188 123 7859 712 5229 257 4836 603 9896 756 2985 140 7434 174 9832 268 4528 206 3563 324 9411 70 8143 243 7504 797 812 956 1211 759 262 148 2022 860 53 874 653 870 3600 384 7685 975 6656 393 9333 433 995 883 3140 535 4174 174 6356 36 2295 813 8126 491 8483 53 2543 303 9996 667 7074 27 5798 418 5118 932 6243 85 2114 573 548 914 9039 835 498 64 9334 835 9884 170 947 280 5363 580 2745 296 371 388 382 538 739 684 5960 912 6223 880 9161 59 7845 555 4360 568 8030 767 1857 781 6030 548 9423 960 9807 479 9527 489 7753 671 151 182 8677 348 3920 88 4659 65 1761 172 3961 363 2165 316 3070 969 830 110 2902 655 866 349 4863 94 7717 63 1789 678 1752 335 6690 238 6066 716 9873 723 1197 720 5203 695 8948 757 4842 148 6826 981 4469 760 2092 881 6004 155 762 68 7693 719 7154 201 7951 518 7823 474 7286 763 5906 761 3630 409 2494 28 2013 24 4457 757 8970 922 3616 784 2483 616 5642 232 4143 786 1249 219 7568 998 366 956 6380 856 1251 242 9772 444 9245 551 3894 247 9706 443 8775 452 2152 786 5187 245 6320 667 7136 16 5905 275 5633 941 2576 760 9887 764 2447 514 3902 724 8861 423 6734 505 8125 613 6111 717 6970 685 5370 474 4522 366 3836 623 2033 328 804 233 4232 722 7520 651 3838 869 2404 337 4351 657 1611 561 5251 785 5874 499 5978 379 6162 402 2805 690 8493 75 2054 544 3996 662 8395 837 2055 794 1672 653 5589 125 1908 705 9061 132 7798 771 6572 912 3871 80 2785 161 3162 809 2503 831 5203 539 9962 495 9397 967 716 378 6359 788 736 716 3432 444 9895 675 6969 339 2315 750 7594 767 7353 264 3177 204 5411 92 5271 463 1253 939 6540 830 6711 301 5357 653 548 196 188 988 121 342 4416 607 3696 324 2517 597 3582 654 9317 693 1258 978 471 573 6816 612 6520 501 8342 767 8665 612 6333 13 8440 913 4315 180 7458 925 3064 505 6456 182 1750 433 2592 750 8325 261 4398 429 4327 589 835 52 2415 832 822 379 128 531 7809 382 3236 248 1310 659 8811 801 754 70 310 597 2777 577 5859 305 1779 54 5433 314 2270 919 6871 506 2661 951 5514 121 9016 458 12 854 2444 850 9716 342 9094 635 9562 939 1507 577 7722 497 1834 32 5485 117 741 677 611 278 5452 707 9635 544 4883 800 4535 638 1638 624 7362 464 2659 713 421 422 8312 185 3601 348 1693 117 3518 109 9011 388 7132 452 686 771 2985 177 0 169 3171 392 2519 341 7487 568 6152 366 3050 803 781 580 654 641 7948 485 6696 185 3832 506 3800 130 8317 779 6042 535 6135 240 5731 58 5058 281 3999 450 1128 768 5801 351 1415 773 3916 412 7986 810 5304 174 1146 543 3351 21 6525 313 1489 280 8991 478 8958 997 2150 132 5451 225 7771 83 4607 221 4047 487 4959 218 1514 763 3839 478 5995 978 4379 990 7979 432 2342 294 8915 552 5697 535 4433 54 5823 880 4342 479 1096 776 3906 983 4522 850 6227 892 3863 425 1930 90 9900 126 9839 574 3007 545 8215 590 5644 388 7923 688 2352 429 4972 673 3622 93 1628 66 1201 60 1696 150 3706 888 7628 822 1003 718 606 568 7915 359 2326 605 4204