Submission #1693871


Source Code Expand

#include <cstdio>
#include <algorithm>
int N, X, Y, Z;
long long O;
std::pair < long long, long long > p[100001], q[100001];
std::pair < long long, std::pair < int, int > > check(long long mid)
{
	int i = 1, j = 1, gi = 0, gj = 0;
	long long s = 0;
	while (gi + gj < X + Y)
	{
		while (i <= N && p[i].first + mid < p[i].second)
			i++;
		if (i > N)
			break;
		while (j <= N && q[j].first + mid >= q[j].second)
			j++;
		if (j > N)
			break;
		if (p[i].first + mid >= q[j].second)
		{
			gi++;
			s += p[i++].first;
		}
		else
		{
			gj++;
			s += q[j++].second;
		}
	}
	while (gi + gj < X + Y)
	{
		while (i <= N && p[i].first + mid < p[i].second)
			i++;
		if (i > N)
			break;
		gi++;
		s += p[i++].first;
	}
	while (gi + gj < X + Y)
	{
		while (j <= N && q[j].first + mid >= q[j].second)
			j++;
		if (j > N)
			break;
		gj++;
		s += q[j++].second;
	}
	i = 1, j = 1;
	int Gi = 0, Gj = 0;
	long long S = 0;
	while (Gi + Gj < X + Y)
	{
		while (i <= N && p[i].first + mid <= p[i].second)
			i++;
		if (i > N)
			break;
		while (j <= N && q[j].first + mid > q[j].second)
			j++;
		if (j > N)
			break;
		if (p[i].first + mid > q[j].second)
		{
			Gi++;
			S += p[i++].first;
		}
		else
		{
			Gj++;
			S += q[j++].second;
		}
	}
	while (Gi + Gj < X + Y)
	{
		while (i <= N && p[i].first + mid <= p[i].second)
			i++;
		if (i > N)
			break;
		Gi++;
		S += p[i++].first;
	}
	while (Gi + Gj < X + Y)
	{
		while (j <= N && q[j].first + mid > q[j].second)
			j++;
		if (j > N)
			break;
		Gj++;
		S += q[j++].second;
	}
	return { S - mid * (X - Gi), { Gi, gi } };
}
int main()
{
	scanf("%d%d%d", &X, &Y, &Z);
	N = X + Y + Z;
	for (int i = 1; i <= N; i++)
	{
		long long a, b, c;
		scanf("%lld%lld%lld", &a, &b, &c);
		O += c;
		p[i] = q[i] = std::make_pair(a - c, b - c);
	}
	std::sort(p + 1, p + N + 1, [] (const auto &i, const auto &j) { return i.first > j.first; });
	std::sort(q + 1, q + N + 1, [] (const auto &i, const auto &j) { return i.second > j.second; });
	long long l = -1000000000, r = 1000000000;
	while (l < r)
	{
		long long m = l + r >> 1;
		std::pair < long long, std::pair < int, int > > ans = check(m);
		if (ans.second.first <= X && X <= ans.second.second)
		{
			printf("%lld\n", O + ans.first);
			return 0;
		}
		if (ans.second.second < X)
			l = m + 1;
		else
			r = m - 1;
	}
	while (1);
}

Submission Info

Submission Time
Task C - Coins
User NiroBC
Language C++14 (GCC 5.4.1)
Score 800
Code Size 2434 Byte
Status AC
Exec Time 80 ms
Memory 3328 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:95:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &X, &Y, &Z);
                             ^
./Main.cpp:100:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld", &a, &b, &c);
                                    ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 3
AC × 35
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt, subtask_1_18.txt, subtask_1_19.txt, subtask_1_20.txt, subtask_1_21.txt, subtask_1_22.txt, subtask_1_23.txt, subtask_1_24.txt, subtask_1_25.txt, subtask_1_26.txt, subtask_1_27.txt, subtask_1_28.txt, subtask_1_29.txt
Case Name Status Exec Time Memory
sample_01.txt AC 1 ms 128 KB
sample_02.txt AC 1 ms 128 KB
sample_03.txt AC 1 ms 128 KB
subtask_1_01.txt AC 0 ms 128 KB
subtask_1_02.txt AC 8 ms 640 KB
subtask_1_03.txt AC 11 ms 1152 KB
subtask_1_04.txt AC 29 ms 1792 KB
subtask_1_05.txt AC 34 ms 2048 KB
subtask_1_06.txt AC 54 ms 2560 KB
subtask_1_07.txt AC 10 ms 896 KB
subtask_1_08.txt AC 36 ms 2816 KB
subtask_1_09.txt AC 11 ms 768 KB
subtask_1_10.txt AC 58 ms 2432 KB
subtask_1_11.txt AC 73 ms 3328 KB
subtask_1_12.txt AC 37 ms 3328 KB
subtask_1_13.txt AC 58 ms 3328 KB
subtask_1_14.txt AC 58 ms 3328 KB
subtask_1_15.txt AC 67 ms 3328 KB
subtask_1_16.txt AC 41 ms 3328 KB
subtask_1_17.txt AC 45 ms 3328 KB
subtask_1_18.txt AC 44 ms 3328 KB
subtask_1_19.txt AC 60 ms 3328 KB
subtask_1_20.txt AC 76 ms 3328 KB
subtask_1_21.txt AC 35 ms 3328 KB
subtask_1_22.txt AC 80 ms 3328 KB
subtask_1_23.txt AC 61 ms 3328 KB
subtask_1_24.txt AC 59 ms 3328 KB
subtask_1_25.txt AC 40 ms 3328 KB
subtask_1_26.txt AC 53 ms 3328 KB
subtask_1_27.txt AC 46 ms 3328 KB
subtask_1_28.txt AC 60 ms 3328 KB
subtask_1_29.txt AC 0 ms 128 KB