답안 #836650

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
836650 2023-08-24T13:42:19 Z billyisme Feast (NOI19_feast) C++14
100 / 100
103 ms 12784 KB
/***************************************************************
*             Author : Nguyen Trong Van Viet                   *
*                        Age : 17                              *
*      School : 12T2 Le Khiet High School for the Gifted       *
*            Hometown :  Quang Ngai , Viet Nam .               *
* Khanh An is my lover :) the more I code  , the nearer I am   *
****************************************************************/
#define TASK "text"
#define INPUT TASK".INP" 
#define OUTPUT TASK".OUT"

bool mtt = 0 ;
int test = 1 ;  

#include<bits/stdc++.h>
using namespace std; 

#define int long long 
#define             ll  long long 
#define             db  double 
#define             ve  vector 
#define             vi  vector<int>
#define            vll  vector<ll>
#define            str  string
#define             pb  push_back
#define             pk  pop_back
#define             el  '\n'
#define            pii  pair<int,int>
#define            pll  pair<ll,ll>
#define             mp  make_pair 
#define             fi  first 
#define             se  second
#define         uni(a)  sort(all(a)),a.resize(unique(all(a))-a.begin()) 
#define     FOR(i,a,b)  for(int i=(int)(a);i<=(int)(b);i++)
#define    FORD(i,a,b)  for(int i=(int)(a);i>=(int)(b);i--)
#define    FORN(i,a,b)  for(int i=(int)(a);i<(int)(b);i++)
#define         all(a)  a.begin(),a.end()  
#define           btpc  __builtin_popcountll
#define             LB  lower_bound
#define             UB  upper_bound 
#define            tct  template<class T>
#define     BIT(msk,i)  (msk>>(i)&1)

ll lg(ll a){return __lg(a);}
ll sq(ll a){return a*a;}  
ll gcd(ll a,ll b){return __gcd(a,b);} 
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll rd(ll l , ll r ){return l+1LL*rand()*rand()*rand()%(r-l+1);}
#define prt(a,n) FOR(i,1,n)cout<<a[i]<<" ";cout<<el;
#define prv(a) for(auto v:a)cout<<v<<" "; cout<<el; 

tct bool mini(T& a,T b){return (a>b)?a=b,1:0;}
tct bool maxi(T& a,T b){return (a<b)?a=b,1:0;}

int xx[] = {0,0,-1,0,1}; 
int yy[] = {0,-1,0,1,0};

const db PI = acos(-1) , EPS = 1e-9;
const ll inf = 1e18 , cs = 331 , sm = 1e9+7; 
const int N = 3e5+5 , oo = 2e9 , LO = 17 , CH = 26 ; 

int n , k; 
int a[N] ; 
ll s[N] ; 
void doc()
{
    cin>> n >> k; 
    FOR(i,1,n)cin>>a[i] , s[i]=s[i-1]+a[i] ; 
}

namespace sub1
{
	pll f[N] ;
	pll CK(ll x)
	{
		f[0] = {0,0};
    // f[i] = s[i]+(f[j]-s[j]+x);
	    pii curmx = {x,-1};
	    FOR(i,1,n+1){
	        f[i] = max(f[i-1],mp(curmx.fi+s[i],curmx.se));
	        maxi(curmx,mp(f[i].fi-s[i]+x,f[i].se-1));
	        // trace(i,f[i].fi,f[i].se);
	    }
	    // return -f[n].se<=k ;
	    return mp(f[n].fi,-f[n].se);
	}
    void xuly()
    {
    	ll l = -1e12 ; 
    	ll r=  1e12 ;
    	ll ans = 0 ; 
    	while(l<=r)
    	{
    		ll mid =(l+r)/2 ; 
    		pll x= CK(mid);
    		if(x.se<=k)
    		{
    			maxi(ans,-mid*x.se+x.fi) ;
    			l=mid+1 ;
    		} 
    		else r=mid-1 ;
    	}
    	cout<<ans;
    }
}

/*  DON'T BELIEVE LOVE WILL INSPIRE YOU ->  TRAIN HARDER ->  YOU WILL GET THE LOVE YOU WANT !!*/

signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);srand(time(0)); 
    if(fopen(INPUT,"r"))
    {
        freopen(INPUT ,"r",stdin);
        freopen(OUTPUT,"w",stdout);
    }
    if(mtt)cin>>test;

    FOR(i,1,test)
    {
        doc() ; 
        sub1::xuly() ; 
    }
    cerr<<el<<"Love KA : " << clock() <<"ms"<<el;
}

Compilation message

feast.cpp: In function 'int main()':
feast.cpp:114:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  114 |         freopen(INPUT ,"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~
feast.cpp:115:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  115 |         freopen(OUTPUT,"w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 9328 KB Output is correct
2 Correct 75 ms 9548 KB Output is correct
3 Correct 74 ms 9688 KB Output is correct
4 Correct 56 ms 9556 KB Output is correct
5 Correct 54 ms 9556 KB Output is correct
6 Correct 62 ms 9420 KB Output is correct
7 Correct 53 ms 9384 KB Output is correct
8 Correct 69 ms 9588 KB Output is correct
9 Correct 54 ms 9368 KB Output is correct
10 Correct 64 ms 9536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 9628 KB Output is correct
2 Correct 52 ms 9936 KB Output is correct
3 Correct 48 ms 9684 KB Output is correct
4 Correct 52 ms 9800 KB Output is correct
5 Correct 53 ms 9636 KB Output is correct
6 Correct 43 ms 9708 KB Output is correct
7 Correct 55 ms 9940 KB Output is correct
8 Correct 57 ms 9904 KB Output is correct
9 Correct 59 ms 9648 KB Output is correct
10 Correct 50 ms 9812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 9792 KB Output is correct
2 Correct 73 ms 9676 KB Output is correct
3 Correct 67 ms 9820 KB Output is correct
4 Correct 81 ms 9736 KB Output is correct
5 Correct 69 ms 9824 KB Output is correct
6 Correct 72 ms 9880 KB Output is correct
7 Correct 75 ms 9804 KB Output is correct
8 Correct 75 ms 9780 KB Output is correct
9 Correct 67 ms 9856 KB Output is correct
10 Correct 69 ms 9836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 9328 KB Output is correct
2 Correct 75 ms 9548 KB Output is correct
3 Correct 74 ms 9688 KB Output is correct
4 Correct 56 ms 9556 KB Output is correct
5 Correct 54 ms 9556 KB Output is correct
6 Correct 62 ms 9420 KB Output is correct
7 Correct 53 ms 9384 KB Output is correct
8 Correct 69 ms 9588 KB Output is correct
9 Correct 54 ms 9368 KB Output is correct
10 Correct 64 ms 9536 KB Output is correct
11 Correct 51 ms 9628 KB Output is correct
12 Correct 52 ms 9936 KB Output is correct
13 Correct 48 ms 9684 KB Output is correct
14 Correct 52 ms 9800 KB Output is correct
15 Correct 53 ms 9636 KB Output is correct
16 Correct 43 ms 9708 KB Output is correct
17 Correct 55 ms 9940 KB Output is correct
18 Correct 57 ms 9904 KB Output is correct
19 Correct 59 ms 9648 KB Output is correct
20 Correct 50 ms 9812 KB Output is correct
21 Correct 69 ms 9792 KB Output is correct
22 Correct 73 ms 9676 KB Output is correct
23 Correct 67 ms 9820 KB Output is correct
24 Correct 81 ms 9736 KB Output is correct
25 Correct 69 ms 9824 KB Output is correct
26 Correct 72 ms 9880 KB Output is correct
27 Correct 75 ms 9804 KB Output is correct
28 Correct 75 ms 9780 KB Output is correct
29 Correct 67 ms 9856 KB Output is correct
30 Correct 69 ms 9836 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 2 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 336 KB Output is correct
56 Correct 2 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 99 ms 12448 KB Output is correct
62 Correct 102 ms 12784 KB Output is correct
63 Correct 77 ms 12420 KB Output is correct
64 Correct 99 ms 12660 KB Output is correct
65 Correct 103 ms 12652 KB Output is correct
66 Correct 101 ms 12616 KB Output is correct
67 Correct 100 ms 12364 KB Output is correct
68 Correct 71 ms 12668 KB Output is correct
69 Correct 68 ms 12364 KB Output is correct
70 Correct 66 ms 12364 KB Output is correct