Submission #503378

#TimeUsernameProblemLanguageResultExecution timeMemory
503378lukameladzeSchools (IZhO13_school)C++14
55 / 100
2070 ms16184 KiB
# include <bits/stdc++.h> #define f first #define s second #define pb push_back #define pii pair <int, int> using namespace std; const int N = 3e5 + 5; int n,m,k,a[N],b[N],sum,num,ans,pr[N],sf[N]; multiset <int> s; vector <pii> v; main() { cin>>n>>m>>k; for (int i = 1; i <= n; i++) { cin>>a[i]>>b[i]; v.pb({a[i] - b[i], i}); } sort(v.begin(),v.end()); reverse(v.begin(),v.end()); for (int i = 0; i < v.size(); i++) { num = a[v[i].s]; if (s.size() < m) { s.insert(num); sum += num; } else { if (*(s.begin()) < num) { sum -= *(s.begin()); s.erase(s.begin()); sum += num; s.insert(num); } } pr[i] = sum; } sum = 0; s.clear(); for (int i = (int)v.size() - 1; i >= 0; i--) { num = b[v[i].s]; if (s.size() < k) { s.insert(num); sum += num; } else { if (*(s.begin()) < num) { sum -= *(s.begin()); s.erase(s.begin()); sum += num; s.insert(num); } } sf[i] = sum; } for (int i = m; i <= n - k; i++) { ans = max(ans, pr[i] + sf[i + 1]); // cout<<i<<" "<<pr[i]<<" "<<sf[i + 1]<<endl; } cout<<ans<<endl; }

Compilation message (stderr)

school.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main() {
      | ^~~~
school.cpp: In function 'int main()':
school.cpp:18:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
school.cpp:20:22: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |         if (s.size() < m) {
      |                      ^
school.cpp:35:22: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   35 |         if (s.size() < k) {
      |                      ^
#Verdict Execution timeMemoryGrader output
Fetching results...