#include <queue> // std::priority_queue
#include <iostream>
#include <cstdio>
#define i4 long
#define i8 long long
#define nmax 2000
i4 k[nmax*(nmax+1)/2];
i8 w[nmax*(nmax+1)/2];
using namespace std;
int main()
{
std::priority_queue<i4> q;
i4 n,nn, h=0,x, i;
i8 s=0;
cin.sync_with_stdio(false);
cin >>n;// scanf("%ld",&n);
nn=n*(n+1)/2;
for(i=0; i<n; i++)
{
cin >>x;// scanf("%ld",&x);
h=max(h,x);
q.push(x);
}
for(; i<nn; i++)
{
cin >>x;// scanf("%ld",&x);
if(x<h)
{
q.pop();
q.push(x);
h=q.top();
}
}
for(i=0; i<n; i++)
{
s+=q.top();
q.pop();
}
cout <<s <<endl;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #include <queue> // std::priority_queue #include <iostream> #include <cstdio> #define i4 long #define i8 long long #define nmax 2000 i4 k[nmax*(nmax+1)/2]; i8 w[nmax*(nmax+1)/2]; using namespace std; int main() { std::priority_queue<i4> q; i4 n,nn, h=0,x, i; i8 s=0; cin.sync_with_stdio(false); cin >>n;// scanf("%ld",&n); nn=n*(n+1)/2; for(i=0; i<n; i++) { cin >>x;// scanf("%ld",&x); h=max(h,x); q.push(x); } for(; i<nn; i++) { cin >>x;// scanf("%ld",&x); if(x<h) { q.pop(); q.push(x); h=q.top(); } } for(i=0; i<n; i++) { s+=q.top(); q.pop(); } cout <<s <<endl; } |
English