Submission #6819714


Source Code Expand

Copy
#include <bits/stdc++.h>

using namespace std;

int n, m, par[100005], ans;
pair<int, int> p[100005];

int find(int a) {
	return par[a] == a ? a : par[a] = find(par[a]);
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
		scanf("%d%d", &p[i].second, &p[i].first);
	sort(p, p + n);
	for (int i = 0; i <= m; i++)
		par[i] = i;
	for (int i = n - 1; i >= 0; i--) {
		if (p[i].second > m)
			continue;
		int ta = find(m - p[i].second);
		if (ta == m)
			continue;
		ans += p[i].first;
		par[ta] = ta ? ta - 1 : m;
	}
	printf("%d\n", ans);
}

Submission Info

Submission Time
Task D - Summer Vacation
User nhho
Language C++14 (GCC 5.4.1)
Score 400
Code Size 584 Byte
Status AC
Exec Time 27 ms
Memory 1536 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:13:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
                       ^
./Main.cpp:15:43: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &p[i].second, &p[i].first);
                                           ^

Judge Result

Set Name All Sample
Score / Max Score 400 / 400 0 / 0
Status
AC × 21
AC × 3
Set Name Test Cases
All sample_01, sample_02, sample_03, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15, testcase_16, testcase_17, testcase_18
Sample sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
sample_01 AC 1 ms 256 KB
sample_02 AC 1 ms 256 KB
sample_03 AC 1 ms 256 KB
testcase_01 AC 5 ms 640 KB
testcase_02 AC 2 ms 384 KB
testcase_03 AC 20 ms 1024 KB
testcase_04 AC 27 ms 1408 KB
testcase_05 AC 27 ms 1536 KB
testcase_06 AC 25 ms 1152 KB
testcase_07 AC 26 ms 1408 KB
testcase_08 AC 8 ms 640 KB
testcase_09 AC 17 ms 1024 KB
testcase_10 AC 25 ms 1408 KB
testcase_11 AC 23 ms 1280 KB
testcase_12 AC 7 ms 512 KB
testcase_13 AC 26 ms 1408 KB
testcase_14 AC 23 ms 1280 KB
testcase_15 AC 3 ms 384 KB
testcase_16 AC 25 ms 1408 KB
testcase_17 AC 5 ms 384 KB
testcase_18 AC 26 ms 1408 KB