codeforces 670D2 - Magic Powder - 2

和前面的那道题一样,就只改了数组的大小和数据类型。

#include <bits/stdc++.h>

using namespace std;
const int MAX = 1e5 + 5;
//int a[MAX], b[MAX], c[MAX];
typedef __int64 ll;
struct NODE
{
	ll a, b, c;
}node[MAX];
ll sum[MAX];
bool comp(NODE a, NODE b)
{
	return a.c < b.c;
}

const int INF = 0x3f3f3f;
int main()
{
	ll n, k;
	scanf("%I64d%I64d", &n, &k);
	int tot = 0;
	for (int i = 0; i < n; ++i)
	{
		scanf("%I64d", &node[i].a);
	//	tot += node[i].a;
	}
	for (int i = 0; i < n; ++i)
	{
		scanf("%I64d", &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;
	ll i = 0;
	ll 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;
}
时间: 2024-10-15 19:18:46

codeforces 670D2 - Magic Powder - 2的相关文章

CodeForces - 670D2 Magic Powder - 2 (二分&amp;模拟)

CodeForces - 670D2 Magic Powder - 2 Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description The term of this problem is the same as the previous one, the only exception - increased restrictions. Input Th

Codeforces 670D2 Magic Powder - 2 二分答案

Waking up in the morning, Apollinaria decided to bake cookies. To bake one cookie, she needs n ingredients, and for each ingredient she knows the value ai - how many grams of this ingredient one needs to bake a cookie. To prepare one cookie Apollinar

CodeForces - 670D1 Magic Powder - 1 (模拟)

CodeForces - 670D1 Magic Powder - 1 Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description This problem is given in two versions that differ only by constraints. If you can solve this problem in large c

Codeforces 670D. Magic Powder

Waking up in the morning, Apollinaria decided to bake cookies. To bake one cookie, she needs n ingredients, and for each ingredient she knows the value ai - how many grams of this ingredient one needs to bake a cookie. To prepare one cookie Apollinar

codeforces 670D1 - Magic Powder - 1

题目的意思,就是给出制作一种食物的每种材料所需的量,然后再给出每种材料目前总共的数量,问最多可以制作多少个这样的食物. 贪心.首先求出每种材料是总共有多少个这样的材料,然后由小到大排序,然后再用一个数组存那个后一个大的量的材料减去前面所有小的量的差,因为比如,有3种材料,每种材料的量分别是1, 2,4, 就需要sum[1] = 1, sum[2] = 3,然后就是贪心的计算了. #include <bits/stdc++.h> using namespace std; const int MA

Magic Powder - 1 CodeForces - 670D1

This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you

Magic Powder - 2 (CF 670_D)

http://codeforces.com/problemset/problem/670/D2 The term of this problem is the same as the previous one, the only exception — increased restrictions. Input The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109) — the nu

[递推+矩阵快速幂]Codeforces 1117D - Magic Gems

传送门:Educational Codeforces Round 60 – D 题意: 给定N,M(n <1e18,m <= 100) 一个magic gem可以分裂成M个普通的gem,现在需要N个gem,可以选择一定的magic gem,指定每一个分裂或不分裂,问一共有多少种方案 两种分裂方案不同当且仅当magic gem的数量不同,或者分裂的magic gem的索引不同. 思路: 1.首先从dp的角度出发 设F(i)为最终需要i个gem的方案数,容易得到递推式: (总方案数 = 最右边的m

【模拟】Codeforces 710C Magic Odd Square

题目链接: http://codeforces.com/problemset/problem/710/C 题目大意: 构造一个N*N的幻方.任意可行解. 幻方就是每一行,每一列,两条对角线的和都相等. 题目思路: [模拟] 分为奇幻方.单偶幻方和双偶幻方三种构造. 具体分类可以查看百度.幻方的N种构造方法 1 // 2 //by coolxxx 3 //#include<bits/stdc++.h> 4 #include<iostream> 5 #include<algori