Submission #857259

# Submission time Handle Problem Language Result Execution time Memory
857259 2023-10-05T16:54:27 Z hariaakas646 Schools (IZhO13_school) C++17
20 / 100
96 ms 6644 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.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);
      |   ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 1 ms 348 KB Execution killed with signal 11
7 Runtime error 2 ms 604 KB Execution killed with signal 11
8 Incorrect 1 ms 348 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 2 ms 604 KB Output isn't correct
12 Incorrect 2 ms 604 KB Output isn't correct
13 Incorrect 9 ms 1112 KB Output isn't correct
14 Incorrect 24 ms 2812 KB Output isn't correct
15 Correct 44 ms 4716 KB Output is correct
16 Incorrect 82 ms 5196 KB Output isn't correct
17 Incorrect 74 ms 5872 KB Output isn't correct
18 Incorrect 74 ms 6132 KB Output isn't correct
19 Incorrect 84 ms 6388 KB Output isn't correct
20 Incorrect 96 ms 6644 KB Output isn't correct