# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
363218 | Ruxandra985 | 학교 설립 (IZhO13_school) | C++14 | 363 ms | 14700 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define DIMN 300010
using namespace std;
int x[DIMN] , y[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 , 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;
it = w.end();
while (idx < s){
it--;
idx++;
suma += *it;
aux = *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] >= aux){ /// ai o pb, il adaugi
suma -= aux;
suma += y[v[i - m].second];
it++;
aux = (*it);
}
w.insert(y[v[i - m].second]);
/// scoti i ul din multiset
if (y[v[i].second] >= aux){ /// ai o pb
suma -= y[v[i].second];
it--;
suma += *it;
aux = *it;
}
w.erase(y[v[i].second]);
/// it vreau sa fie prima pozitie a lui aux
sol = max(sol , suma);
}
fprintf (fout,"%lld",sol);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |