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;
multiset<int> m ;
int d1[MAXN] , d2[MAXN] ;
int resp ;
void tira()
{
resp -= *m.begin() ;
m.erase( m.begin() ) ;
}
void calc (int val, int cons , int n, int S, int d , int a[])
{
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 a[])
{
calc(1,d,n,start,d,a) ;
return d1[d] ;
}
Compilation message (stderr)
holiday.cpp: In function 'void calc(int, int, int, int, int, int*)':
holiday.cpp:35:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(m.size() > cons - abs(i - S))
~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
holiday.cpp:37: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... |