Codeforces 670d1-magic Powder-1

Source: Internet
Author: User

The title of the topic is to give the amount of material needed to produce a single food, and then give the total quantity of each material, and ask how many such foods can be produced at most.

Greedy. First find out how many of each material is the total number of such materials, and then from small to large sort, and then use an array to save the latter a large amount of material minus the front all the small amount of difference, because for example, there are 3 kinds of materials, each material quantity is 1, 2, 4, need sum[1] = 1, sum[2] = 3, then the greedy calculation.

#include <bits/stdc++.h>using namespace Std;const int MAX = 1e3 + 5;//int A[max], B[max], c[max];struct node{int A, b, C;} Node[max];int Sum[max];bool Comp (Node A, Node B) {return A.C < B.C;} const INT INF = 0x3f3f3f;int Main () {int n, k;scanf ("%d%d", &n, &k); int tot = 0;for (int i = 0; i < n; ++i) {scan F ("%d", &node[i].a);//tot + = node[i].a;} for (int i = 0; i < n; ++i) {scanf ("%d", &node[i].b);//k + = node[i].b;} int smallest = inf;for (int i = 0; i < n; ++i) {node[i].c = node[i].b/node[i].a;//if (Smallest > C[i])//smallest = C[i];} Sort (node, node + N, comp); Sum[0] = node[0].a;for (int i = 1; i < n; ++i) {sum[i] = sum[i-1] + node[i].a;} for (int i = 0; i < n; ++i)//cout << node[i].c << Endl;int i = 0; int res = Node[0].c;while (i <= n-1 && k > 0) {//cout << k << endl;k + = (node[i].b% node[i].a) ;//cout << "ss" << K << endl;if (k >= (sum[i]* (node[i + 1].c-node[i].c)) && node[i + 1].c! = 0 && node[i + 1].c > node[i].c) {k-= (sum[i] * (Node[i + 1].c-node[i].c)), res + = Node[i + 1].c- Node[i].c;//cout << "k =" << k << Endl;} else if (K < (sum[i]* (node[i + 1].c-node[i].c)) && node[i + 1].c! = 0 && node[i + 1].c > Node[i]. c) {//if (node[i + 1].c > node[i].c)//{res + = k/(Sum[i]), Break;//}}else if (node[i + 1].a = = 0) {res + = k/(Sum[i]);// cout << "Here" << Endl;break;} Else//break;i++;//cout << "res" << res << Endl;} cout << Res << Endl;return 0;}


Codeforces 670d1-magic Powder-1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.