Submission #363234

# Submission time Handle Problem Language Result Execution time Memory
363234 2021-02-05T10:21:39 Z Ruxandra985 Schools (IZhO13_school) C++14
25 / 100
611 ms 15340 KB
#include <bits/stdc++.h>
#define DIMN 300010
using namespace std;
int x[DIMN] , y[DIMN];
pair <int , int> v[DIMN];
multiset <int> w , p;
int cmp (pair <int , int> a , pair <int , int> b){
    return a > b;
}
int main()
{
    FILE *fin = stdin;
    FILE *fout = stdout;
    int n , m , s , i , aux ,idx;
    long long suma , sol = 0;
    multiset<int> :: iterator it , it2;
    fscanf (fin,"%d%d%d",&n,&m,&s);
    for (i = 1 ; i <= n ; i++){
        fscanf (fin,"%d%d",&x[i],&y[i]);

        v[i] = make_pair(x[i] - y[i] , i);

    }

    sort (v + 1 , v + n + 1 , cmp);
    /// v = ordinea prioritatilor

    suma = 0;

    for (i = 1 ; i <= m ; i++){
        suma += x[v[i].second];
    }

    for (i = m + 1 ; i <= n ; i++){
        w.insert(y[v[i].second]);
    }



    idx = 0;

    while (idx < s){
        it = w.end();
        it--;
        idx++;
        p.insert(*it);
        w.erase(it);
        suma += *it;
    }
    /// aux e cea mai mica valoare luata din sufixul ala

    sol = suma;

    for (i = m + 1 ; i <= n ; i++){
        suma -= x[v[i - m].second];
        suma += x[v[i].second];

        /// cele mai mari s uri

        /// adaugi i - m ul

        if (y[v[i - m].second] >= *p.begin()){ /// ai o pb, il adaugi
            suma -= *p.begin();
            suma += y[v[i - m].second];

            w.insert(*p.begin());
            p.erase(p.begin());
            p.insert(y[v[i - m].second]);


        }
        else w.insert(y[v[i - m].second]);

        /// scoti i ul din multiset

        if (y[v[i].second] >= *p.begin()){ /// ai o pb, era in p
            suma -= y[v[i].second];
            p.erase(p.lower_bound(y[v[i].second]));

            it = w.end();
            it--;
            p.insert(*it);
            w.erase(it);

            suma += *it;


        }
        else w.erase(w.lower_bound(y[v[i].second]));
        /// it vreau sa fie prima pozitie a lui aux


        sol = max(sol , suma);
    }
    fprintf (fout,"%lld",sol);
    return 0;
}

Compilation message

school.cpp: In function 'int main()':
school.cpp:14:25: warning: unused variable 'aux' [-Wunused-variable]
   14 |     int n , m , s , i , aux ,idx;
      |                         ^~~
school.cpp:17:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |     fscanf (fin,"%d%d%d",&n,&m,&s);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
school.cpp:19:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |         fscanf (fin,"%d%d",&x[i],&y[i]);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Incorrect 1 ms 364 KB Output isn't correct
7 Incorrect 4 ms 620 KB Output isn't correct
8 Correct 2 ms 492 KB Output is correct
9 Incorrect 3 ms 492 KB Output isn't correct
10 Incorrect 3 ms 492 KB Output isn't correct
11 Incorrect 5 ms 620 KB Output isn't correct
12 Incorrect 6 ms 748 KB Output isn't correct
13 Incorrect 16 ms 1408 KB Output isn't correct
14 Incorrect 111 ms 5612 KB Output isn't correct
15 Incorrect 347 ms 11116 KB Output isn't correct
16 Correct 475 ms 11372 KB Output is correct
17 Incorrect 379 ms 10732 KB Output isn't correct
18 Incorrect 408 ms 11752 KB Output isn't correct
19 Incorrect 484 ms 12908 KB Output isn't correct
20 Incorrect 611 ms 15340 KB Output isn't correct