Submission #363267

#TimeUsernameProblemLanguageResultExecution timeMemory
363267Ruxandra985Schools (IZhO13_school)C++14
100 / 100
306 ms18668 KiB
#include <bits/stdc++.h> #define DIMN 300010 using namespace std; int x[DIMN] , y[DIMN]; long long prefix[DIMN] , sufix[DIMN]; pair <int , int> v[DIMN]; multiset <int> w ; 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; 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]; w.insert(x[v[i].second]); prefix[i] = suma; } for (i = m + 1 ; i <= n ; i++){ prefix[i - 1] = suma; w.insert(x[v[i].second]); suma += x[v[i].second]; suma = suma - *w.begin(); w.erase(w.begin()); } prefix[n] = suma; /// ------------------------------------------------------------------ w.clear(); suma = 0; for (i = n ; n - i + 1 <= s ; i--){ suma += y[v[i].second]; w.insert(y[v[i].second]); sufix[i] = suma; } for (i = n - s ; i ; i--){ sufix[i + 1] = suma; w.insert(y[v[i].second]); suma += y[v[i].second]; suma = suma - *w.begin(); w.erase(w.begin()); } sufix[1] = suma; for (i = 0 ; i <= n ; i++){ sol = max(sol , prefix[i] + sufix[i + 1]); } fprintf (fout,"%lld",sol); return 0; }

Compilation message (stderr)

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