Submission #25948674


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
double X, Y;
bool compareX(array<double, 4> a, array<double, 4> b)
{
if ( a[0] == b[0] ) return a[2] > b[2];
return a[0] > b[0];
}
bool compareY(array<double, 4> a, array<double, 4> b)
{
if ( a[1] == b[1] ) return a[2] > b[2];
return a[1] > b[1];
}
bool compareZ(array<double, 4> a, array<double, 4> b)
{
double F = X/Y;
double fa = a[0]/a[1];
double fb = b[0]/b[1];
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <bits/stdc++.h>
using namespace std;
double X, Y;

bool compareX(array<double, 4> a, array<double, 4> b)
{
	if ( a[0] == b[0] ) return a[2] > b[2];
	return a[0] > b[0];
}

bool compareY(array<double, 4> a, array<double, 4> b)
{
	if ( a[1] == b[1] ) return a[2] > b[2];
	return a[1] > b[1];
}

bool compareZ(array<double, 4> a, array<double, 4> b)
{
	double F = X/Y;
	double fa = a[0]/a[1];
	double fb = b[0]/b[1];
	
	return abs(F-fa) < abs(F-fb);
}

int main()
{
	int n;
	cin >> n;
	double maxX = 0, maxY = 0;
	cin >> X >> Y;
	array<double, 4> lunch[n];
	for ( int i = 0 ; i < n ; i++ )
	{
		cin >> lunch[i][0] >> lunch[i][1];
		lunch[i][2] = lunch[i][0]+lunch[i][1];
		lunch[i][3] = 0;
		maxX += lunch[i][0];
		maxY += lunch[i][0];
	}
	
	if ( maxX < X || maxY < Y )
	{
		cout << -1;
		return 0;
	}
	
	int ans = 0;
	int sortUse = -1;
	
	while(X>0||Y>0)
	{
		ans++;
		if ( X > 0 && Y > 0 )
		{
			if ( sortUse != 0 )
			{
				sort(lunch, lunch+n, compareZ);
				sortUse = 0;
			}
		}
		else if ( X > 0 )
		{
			if ( sortUse != 1 )
			{
				sort(lunch, lunch+n, compareX);
				sortUse = 1;
			}
		}
		else
		{
			if ( sortUse != 2 )
			{
				sort(lunch, lunch+n, compareY);
				sortUse = 2;
			}
		}
		
		for ( int i = 0 ; i < n ; i++ )
		{
			if ( lunch[i][3] == 0 )
			{
				lunch[i][3] = 1;
				X -= lunch[i][0];
				Y -= lunch[i][1];
				break;
			}
		}
	}
	
	cout << ans;
}

Submission Info

Submission Time
Task D - Strange Lunchbox
User TanKaiYi0220
Language C++ (GCC 9.2.1)
Score 0
Code Size 1476 Byte
Status WA
Exec Time 2205 ms
Memory 3672 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 2
AC × 31
WA × 16
TLE × 3
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 6 ms 3640 KB
001.txt AC 2 ms 3572 KB
002.txt AC 2 ms 3604 KB
003.txt AC 2 ms 3576 KB
004.txt AC 2 ms 3548 KB
005.txt AC 2 ms 3652 KB
006.txt AC 2 ms 3540 KB
007.txt AC 2 ms 3540 KB
008.txt WA 2 ms 3548 KB
009.txt AC 3 ms 3652 KB
010.txt AC 1 ms 3616 KB
011.txt AC 2 ms 3564 KB
012.txt WA 2 ms 3532 KB
013.txt WA 2 ms 3652 KB
014.txt WA 1 ms 3648 KB
015.txt WA 2 ms 3540 KB
016.txt WA 2 ms 3656 KB
017.txt WA 2 ms 3568 KB
018.txt WA 3 ms 3564 KB
019.txt WA 2 ms 3616 KB
020.txt WA 2 ms 3652 KB
021.txt WA 2 ms 3644 KB
022.txt WA 2 ms 3652 KB
023.txt WA 2 ms 3636 KB
024.txt WA 2 ms 3584 KB
025.txt WA 3 ms 3644 KB
026.txt WA 2 ms 3600 KB
027.txt AC 2 ms 3616 KB
028.txt TLE 2205 ms 3356 KB
029.txt TLE 2205 ms 3372 KB
030.txt AC 8 ms 3672 KB
031.txt AC 2 ms 3564 KB
032.txt AC 2 ms 3552 KB
033.txt AC 2 ms 3640 KB
034.txt AC 2 ms 3544 KB
035.txt AC 3 ms 3652 KB
036.txt AC 2 ms 3544 KB
037.txt AC 2 ms 3532 KB
038.txt AC 2 ms 3636 KB
039.txt AC 6 ms 3576 KB
040.txt AC 2 ms 3640 KB
041.txt AC 2 ms 3600 KB
042.txt AC 2 ms 3548 KB
043.txt AC 3 ms 3560 KB
044.txt AC 3 ms 3532 KB
045.txt TLE 2205 ms 3368 KB
046.txt AC 8 ms 3608 KB
047.txt AC 2 ms 3656 KB
example0.txt AC 2 ms 3600 KB
example1.txt AC 3 ms 3592 KB


2025-02-28 (Fri)
11:19:32 +00:00