Submission #47524

# Submission time Handle Problem Language Result Execution time Memory
47524 2018-05-05T02:10:30 Z ngkan146 Schools (IZhO13_school) C++11
100 / 100
192 ms 41936 KB
// khanh best
#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct school{
   ll m, s, id;
   school(ll m=0,ll s=0,ll id=0): m(m), s(s), id(id) {}
};
ll N,M,S;
school a[300005];
ll sum;
bool cmp(school x,school y){
   return x.m - x.s < y.m - y.s;
}
struct cmpS{
   bool operator ()(school x,school y){
      return x.s > y.s;
   }
};
struct cmpM{
   bool operator ()(school x,school y){
      return x.m - x.s > y.m - y.s;
   }
};
struct cmpM2{
   bool operator ()(school x,school y){
      return x.m > y.m;
   }
};
priority_queue <school,vector<school>,cmpS> pqS;
priority_queue <school,vector<school>,cmpM> pqM;
priority_queue <school,vector<school>,cmpM2> pqM2;
bool usedM[300005];
int main(){
   scanf("%lld %lld %lld",&N,&M,&S);
   for(int i=1;i<=N;i++)
      scanf("%lld %lld",&a[i].m,&a[i].s),
      sum += a[i].m,
      a[i].id = i;
   sort(a+1,a+N+1,cmp);
   for(int i=1;i<=S;i++)
      sum -= (a[i].m - a[i].s);
   for(int i=1;i<=S;i++)
      pqS.push(a[i]);
   for(int i=S+1;i<=N;i++)
      pqM.push(a[i]),
      pqM2.push(a[i]);
   ll zero = N - M - S;

   while(zero--){
      ll canS = pqS.top().s;
      while(usedM[pqM.top().id]) pqM.pop();
      canS += pqM.top().m - pqM.top().s;

      while(usedM[pqM2.top().id]) pqM2.pop();
      ll canM = pqM2.top().m;
      if (canS < canM){
         usedM[pqM.top().id] = 1;
         sum -= canS;
         pqS.pop();
         pqS.push(pqM.top());
         pqM.pop();
      }
      else{
         usedM[pqM2.top().id] = 1;
         sum -= canM;
         pqM2.pop();
      }
   }
   cout << sum;
}

Compilation message

school.cpp: In function 'int main()':
school.cpp:35:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld %lld %lld",&N,&M,&S);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
school.cpp:38:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%lld %lld",&a[i].m,&a[i].s),
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       sum += a[i].m,
       ~~~~~~~~~~~~~^~
       a[i].id = i;
       ~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7416 KB Output is correct
2 Correct 6 ms 7532 KB Output is correct
3 Correct 7 ms 7644 KB Output is correct
4 Correct 6 ms 7664 KB Output is correct
5 Correct 6 ms 7700 KB Output is correct
6 Correct 6 ms 7704 KB Output is correct
7 Correct 9 ms 8084 KB Output is correct
8 Correct 9 ms 8288 KB Output is correct
9 Correct 8 ms 8408 KB Output is correct
10 Correct 8 ms 8472 KB Output is correct
11 Correct 9 ms 8488 KB Output is correct
12 Correct 9 ms 8488 KB Output is correct
13 Correct 26 ms 11372 KB Output is correct
14 Correct 62 ms 14076 KB Output is correct
15 Correct 144 ms 21052 KB Output is correct
16 Correct 102 ms 21052 KB Output is correct
17 Correct 128 ms 26348 KB Output is correct
18 Correct 151 ms 33392 KB Output is correct
19 Correct 168 ms 36964 KB Output is correct
20 Correct 192 ms 41936 KB Output is correct