답안 #857260

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
857260 2023-10-05T17:06:07 Z hariaakas646 학교 설립 (IZhO13_school) C++17
100 / 100
100 ms 6760 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;

void usaco()
{
    freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
//    freopen("problem.out", "w", stdout);
}

int main() {
	// usaco();
	int n, m, p;
	scd(n);
	scd(m);
	scd(p);
	vii vec(n);
	frange(i, n) {
		scd(vec[i].f);
		scd(vec[i].s);
	}
	sort(all(vec), greater<>());
	vb vis(n);
	lli tot = 0;
	frange(i, m) {
		tot += vec[i].f;
		vis[i] = true;
	}
	priority_queue<pii> ms, ns, ns2;

	frange(i, n) {
		if(vis[i]) {
			ms.push(mp(vec[i].s - vec[i].f, i));
			
		}
		else {
			ns.push(mp(vec[i].s, i));
			ns2.push(mp(vec[i].f, i));
		}
	}

	frange(i, p) {
		while(ns.size() && vis[ns.top().s]) ns.pop();
		while(ns2.size() && vis[ns2.top().s]) ns2.pop();
		int e1 = -1e9;

		if(ns.size()) e1 = ns.top().f;
		int e2 = -1e9;

		if(ns2.size() && ms.size()) {
			e2 = ms.top().f + ns2.top().f;
		}

		if(e1 > e2) {
			tot += e1;
			vis[ns.top().s] = true;
			ns.pop();

		}
		else {
			tot += e2;
			auto p = ms.top();
			auto p2 = ns2.top();
			ms.pop();
			ns2.pop();
			vis[p2.s] = true;
			ms.push(mp(vec[p2.s].s - vec[p2.s].f, i));
		}
	}
	printf("%lld", tot);
}

Compilation message

school.cpp: In function 'int main()':
school.cpp:84:9: warning: variable 'p' set but not used [-Wunused-but-set-variable]
   84 |    auto p = ms.top();
      |         ^
school.cpp: In function 'void usaco()':
school.cpp:29:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
school.cpp: In function 'int main()':
school.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
school.cpp:36:2: note: in expansion of macro 'scd'
   36 |  scd(n);
      |  ^~~
school.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
school.cpp:37:2: note: in expansion of macro 'scd'
   37 |  scd(m);
      |  ^~~
school.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
school.cpp:38:2: note: in expansion of macro 'scd'
   38 |  scd(p);
      |  ^~~
school.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
school.cpp:41:3: note: in expansion of macro 'scd'
   41 |   scd(vec[i].f);
      |   ^~~
school.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
school.cpp:42:3: note: in expansion of macro 'scd'
   42 |   scd(vec[i].s);
      |   ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 9 ms 1112 KB Output is correct
14 Correct 23 ms 2764 KB Output is correct
15 Correct 42 ms 4720 KB Output is correct
16 Correct 80 ms 5228 KB Output is correct
17 Correct 74 ms 5872 KB Output is correct
18 Correct 72 ms 6132 KB Output is correct
19 Correct 88 ms 6196 KB Output is correct
20 Correct 100 ms 6760 KB Output is correct