Submission #198836

#TimeUsernameProblemLanguageResultExecution timeMemory
198836ZwariowanyMarcinKisik (COCI19_kisik)C++14
90 / 90
1637 ms65912 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define ss(x) (int) x.size() #define pb push_back #define LL long long #define ld long double #define cat(x) cerr << #x << " = " << x << endl #define FOR(i, j, n) for(int i = j; i <= n; ++i) #define boost cin.tie(0), ios_base::sync_with_stdio(0); using namespace std; const int nax = 1000100; int n, k; pair <int, int> x[nax]; multiset <int> s; vector <int> vec; LL sum = 0; LL ans = 1e18 + 111; void add(int val) { sum += val; s.insert(val); if (ss(s) >= k) { sum -= *--s.end(); s.erase(--s.end()); } } int main() { scanf ("%d%d", &n, &k); for (int i = 1; i <= n; ++i) { scanf ("%d%d", &x[i].se, &x[i].fi); } sort (x + 1, x + n + 1); for (int i = 1; i <= n;) { vec.clear(); int j = i; while (j <= n && x[i].fi == x[j].fi) { vec.pb(x[j].se); j++; } sort(vec.begin(), vec.end()); for (int j = 1; j < ss(vec); ++j) add(vec[j]); if (ss(s) == k - 1) ans = min(ans, 1LL * x[i].fi * (sum + x[i].se)); add(vec[0]); i = j; } printf ("%lld", ans); return 0; }

Compilation message (stderr)

kisik.cpp: In function 'int main()':
kisik.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d%d", &n, &k);
  ~~~~~~^~~~~~~~~~~~~~~~
kisik.cpp:39:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d%d", &x[i].se, &x[i].fi);
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...