This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "holiday.h"
#define lp(i,a,b,v) for(int i=a;i<b;i = i + v)
#define MAXN 100005
#define pb push_back
#define pii pair<int,int>
#define ss second
#define ff first
#define lli long long int
using namespace std;
int S ;
int D ;
int N ;
int a[MAXN] ;
multiset<int> m ;
lli d1[MAXN] , d2[MAXN] ;
lli resp ;
void tira()
{
resp -= *m.begin() ;
m.erase( m.begin() ) ;
}
void calc (int val, int cons)
{
resp = 0 ;
m.clear() ;
for(int i = S ; i < min(S + cons , N ) and i>=max(0, S - cons) ; i += val)
{
resp += a[i] ;
m.insert(a[i]) ;
if(m.size() > cons - abs(i - S))
{
if(cons-abs(i-S) + 1 != m.size() )
{
resp -= *m.begin() ;
m.erase(m.begin()) ;
}
tira() ;
}
if( val == 1 ) d1[cons] = max( resp , d1[cons] );
else d2[cons] = max(resp,d2[cons]) ;
}
// printf("%lld\n", d1[cons]) ;
// printf("%lld\n", d2[cons]) ;
}
long long int findMaxAttraction(int n, int start, int d,
int attraction[])
{
lp(i,0,n,1) a[i] = attraction[i] ;
S = start ;
N = n ;
D = d ;
calc(1,d) ;
return d1[d] ;
}
Compilation message (stderr)
holiday.cpp: In function 'void calc(int, int)':
holiday.cpp:41:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(m.size() > cons - abs(i - S))
~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
holiday.cpp:43:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(cons-abs(i-S) + 1 != m.size() )
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
grader.cpp: In function 'int main()':
grader.cpp:7:12: warning: variable 'n_s' set but not used [-Wunused-but-set-variable]
int i, n_s;
^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |