Submission #63515843


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
int n, m;
long long a[200100], b[200100], ans;
pair<long long, int> mx;
int main() {
scanf ("%d%d", &n, &m);
a[0] = 0LL;
mx.first = 0LL;
mx.second = -1;
for (int i = 1; i <= n; ++i) {
scanf ("%lld", &a[i]);
}
sort (a + 1, a + n + 1, greater<int>());
for (int i = 1; i <= n; ++i) {
a[i] += a[i - 1];
if (make_pair (a[i], i) > mx) {
mx = make_pair (a[i], i);
}
}
b[0] = 0LL;
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <bits/stdc++.h>
using namespace std;
int n, m;
long long a[200100], b[200100], ans;
pair<long long, int> mx;
int main() {
	scanf ("%d%d", &n, &m);
	a[0] = 0LL;
	mx.first = 0LL;
	mx.second = -1;
	for (int i = 1; i <= n; ++i) {
		scanf ("%lld", &a[i]);
	}
	sort (a + 1, a + n + 1, greater<int>());
	for (int i = 1; i <= n; ++i) {
		a[i] += a[i - 1];
		if (make_pair (a[i], i) > mx) {
			mx = make_pair (a[i], i);
		}
	}
	b[0] = 0LL;
	for (int i = 1; i <= m; ++i) {
		scanf ("%lld", &b[i]);
	}
	sort (b + 1, b + m + 1, greater<int>());
	for (int i = 1; i <= m; ++i) {
		b[i] += b[i - 1];
	}
	ans = mx.first;
	for (int i = 1; i <= min (n, m); ++i) {
		if (i <= mx.second) {
			ans = max (ans, mx.first + b[i]);
		} else {
			ans = max (ans, a[i] + b[i]);
		}
	}
	printf ("%lld\n", ans);
	return 0;
}

Submission Info

Submission Time
Task C - Buy Balls
User HappyDavid3367
Language C++ 20 (gcc 12.2)
Score 300
Code Size 842 Byte
Status AC
Exec Time 71 ms
Memory 7004 KB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:7:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |         scanf ("%d%d", &n, &m);
      |         ~~~~~~^~~~~~~~~~~~~~~~
Main.cpp:12:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |                 scanf ("%lld", &a[i]);
      |                 ~~~~~~^~~~~~~~~~~~~~~
Main.cpp:23:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   23 |                 scanf ("%lld", &b[i]);
      |                 ~~~~~~^~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 49
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt, 01_test_33.txt, 01_test_34.txt, 01_test_35.txt, 01_test_36.txt, 01_test_37.txt, 01_test_38.txt, 01_test_39.txt, 01_test_40.txt, 01_test_41.txt, 01_test_42.txt, 01_test_43.txt, 01_test_44.txt, 01_test_45.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3588 KB
00_sample_01.txt AC 1 ms 3692 KB
00_sample_02.txt AC 1 ms 3792 KB
01_test_00.txt AC 1 ms 3704 KB
01_test_01.txt AC 1 ms 3824 KB
01_test_02.txt AC 1 ms 3588 KB
01_test_03.txt AC 36 ms 5476 KB
01_test_04.txt AC 24 ms 4772 KB
01_test_05.txt AC 22 ms 4628 KB
01_test_06.txt AC 70 ms 6704 KB
01_test_07.txt AC 70 ms 6876 KB
01_test_08.txt AC 70 ms 6884 KB
01_test_09.txt AC 70 ms 6752 KB
01_test_10.txt AC 70 ms 6704 KB
01_test_11.txt AC 71 ms 6708 KB
01_test_12.txt AC 70 ms 6996 KB
01_test_13.txt AC 70 ms 6808 KB
01_test_14.txt AC 71 ms 6780 KB
01_test_15.txt AC 61 ms 6628 KB
01_test_16.txt AC 69 ms 7004 KB
01_test_17.txt AC 59 ms 6320 KB
01_test_18.txt AC 69 ms 6880 KB
01_test_19.txt AC 63 ms 6512 KB
01_test_20.txt AC 69 ms 6772 KB
01_test_21.txt AC 59 ms 6608 KB
01_test_22.txt AC 69 ms 6800 KB
01_test_23.txt AC 56 ms 6312 KB
01_test_24.txt AC 69 ms 6656 KB
01_test_25.txt AC 55 ms 6096 KB
01_test_26.txt AC 70 ms 6812 KB
01_test_27.txt AC 60 ms 6560 KB
01_test_28.txt AC 68 ms 6892 KB
01_test_29.txt AC 58 ms 6276 KB
01_test_30.txt AC 69 ms 6776 KB
01_test_31.txt AC 50 ms 5852 KB
01_test_32.txt AC 69 ms 6792 KB
01_test_33.txt AC 53 ms 6200 KB
01_test_34.txt AC 67 ms 6880 KB
01_test_35.txt AC 56 ms 6280 KB
01_test_36.txt AC 67 ms 6800 KB
01_test_37.txt AC 45 ms 5812 KB
01_test_38.txt AC 69 ms 6708 KB
01_test_39.txt AC 50 ms 6108 KB
01_test_40.txt AC 68 ms 6804 KB
01_test_41.txt AC 48 ms 5832 KB
01_test_42.txt AC 68 ms 6744 KB
01_test_43.txt AC 1 ms 3688 KB
01_test_44.txt AC 36 ms 5240 KB
01_test_45.txt AC 36 ms 5248 KB


2025-03-26 (Wed)
13:37:27 +00:00