Submission #441213

#TimeUsernameProblemLanguageResultExecution timeMemory
441213parsabahramiSchools (IZhO13_school)C++17
100 / 100
312 ms19064 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; #define SZ(x) (int) x.size() #define F first #define S second const int N = 3e5 + 10, MOD = 1e9 + 7; int A[N], B[N], ord[N], M[N], m, s, n; set<pii, greater<pii>> st1, st2; int main() { scanf("%d%d%d", &n, &m, &s); for (int i = 1; i <= n; i++) scanf("%d%d", &A[i], &B[i]); /* for (int i = 1; i <= n; i++) scanf("%d", &A[i]); for (int i = 1; i <= n; i++) scanf("%d", &B[i]);*/ iota(ord + 1, ord + n + 1, 1); sort(ord + 1, ord + n + 1, [&] (int a, int b) { return A[a] > A[b]; }); ll sum = 0; for (int i = 1; i <= m; i++) { st1.insert({B[ord[i]] - A[ord[i]], ord[i]}); M[ord[i]] = 1; sum += A[ord[i]]; } for (int i = m + 1; i <= n; i++) st2.insert({B[ord[i]], ord[i]}); int ptr = m + 1; for (int i = 1; i <= s; i++) { while (ptr <= n && M[ord[ptr]]) ptr++; int c1 = (SZ(st1) ? st1.begin()->F + A[ord[ptr]] : -MOD), c2 = (SZ(st2) ? st2.begin()->F : -MOD); if (c2 > c1) { //printf("1 %d ", st2.begin()->S); M[st2.begin()->S] = 1, sum += c2; st2.erase(st2.begin()); } else { M[st1.begin()->S] = 1, sum += c1; st1.erase(st1.begin()); st1.insert({B[ord[ptr]] - A[ord[ptr]], ord[ptr]}); M[ord[ptr]] = 1; st2.erase({B[ord[ptr]], ord[ptr]}); } //printf("%lld\n", sum); } printf("%lld\n", sum); return 0; }

Compilation message (stderr)

school.cpp: In function 'int main()':
school.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf("%d%d%d", &n, &m, &s);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
school.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         scanf("%d%d", &A[i], &B[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...