Submission #857259

#TimeUsernameProblemLanguageResultExecution timeMemory
857259hariaakas646Schools (IZhO13_school)C++17
20 / 100
96 ms6644 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...