답안 #857256

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
857256 2023-10-05T16:52:09 Z hariaakas646 학교 설립 (IZhO13_school) C++17
20 / 100
97 ms 10228 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 = 0;

		if(ns.size()) e1 = ns.top().f;
		int e2 = 0;

		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.f].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 0 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 Incorrect 0 ms 348 KB Output isn't correct
5 Runtime error 1 ms 348 KB Execution killed with signal 11
6 Runtime error 0 ms 348 KB Execution killed with signal 11
7 Runtime error 2 ms 604 KB Execution killed with signal 11
8 Incorrect 2 ms 604 KB Output isn't correct
9 Incorrect 1 ms 348 KB Output isn't correct
10 Incorrect 2 ms 348 KB Output isn't correct
11 Incorrect 3 ms 524 KB Output isn't correct
12 Incorrect 2 ms 600 KB Output isn't correct
13 Incorrect 9 ms 1496 KB Output isn't correct
14 Incorrect 23 ms 3580 KB Output isn't correct
15 Correct 44 ms 6512 KB Output is correct
16 Incorrect 80 ms 7168 KB Output isn't correct
17 Incorrect 74 ms 8448 KB Output isn't correct
18 Incorrect 74 ms 9464 KB Output isn't correct
19 Incorrect 83 ms 9260 KB Output isn't correct
20 Incorrect 97 ms 10228 KB Output isn't correct