답안 #359860

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
359860 2021-01-27T09:08:37 Z shahriarkhan 금 캐기 (IZhO14_divide) C++14
100 / 100
73 ms 9948 KB
#include<bits/stdc++.h>
using namespace std ;

struct tree
{
    vector<int> t ;
    tree(int a[] , int n)
    {
        t = vector<int> (4*n + 4 , 0) ;
        build(a,1,1,n) ;
    }
    void build(int a[] , int node , int low , int high)
    {
        if(low==high) t[node] = a[low] ;
        else
        {
            int mid = (low+high)>>1 , left = node<<1 , right = left|1 ;
            build(a,left,low,mid) , build(a,right,mid+1,high) ;
            t[node] = max(t[left],t[right]) ;
        }
    }
    int query(int node ,int low , int high , int l , int r)
    {
        if(l>high || r<low) return 0 ;
        if(l<=low && high<=r) return t[node] ;
        int mid = (low+high)>>1 , left = node<<1 , right = left|1 ;
        return max(query(left,low,mid,l,r),query(right,mid+1,high,l,r)) ;
    }
};

int bs(int n , long long val , long long pref[] , long long ind[] , int a[])
{
    int low = 1 , high = n ;
    while(low<high)
    {
        int mid = (low+high)>>1 ;
        if((pref[a[mid]]-ind[a[mid]])>=val) high = mid ;
        else low = mid + 1 ;
    }
    return low ;
}

int main()
{
    int n ;
    scanf("%d",&n) ;
    long long pref[n+1] = {0} , ind[n+1] = {0} , gold[n+1] = {0} , pref_g[n+1] = {0} , ans = 0 ;
    int a[n+1] ;
    vector<pair<long long , int> > v ;
    for(int i = 1 ; i <= n ; ++i)
    {
        long long x , g , d ;
        scanf("%lld%lld%lld",&x,&g,&d) ;
        pref[i] = pref[i-1] + d ;
        pref_g[i] = pref_g[i-1] + g ;
        ind[i] = x , gold[i] = g ;
        v.push_back({pref[i] - ind[i],i}) ;
    }
    sort(v.begin(),v.end()) ;
    for(int i = 1 ; i <= n ; ++i) a[i] = v[i-1].second ;
    tree T(a,n) ;
    for(int i = 1 ; i <= n ; ++i)
    {
        int pos = bs(n,pref[i-1] - ind[i],pref,ind,a) ;
        ans = max(ans,pref_g[T.query(1,1,n,pos,n)] - pref_g[i-1]) ;
    }
    printf("%lld\n",ans) ;
    return 0 ;
}

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   46 |     scanf("%d",&n) ;
      |     ~~~~~^~~~~~~~~
divide.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   53 |         scanf("%lld%lld%lld",&x,&g,&d) ;
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 3 ms 748 KB Output is correct
24 Correct 4 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 3 ms 748 KB Output is correct
24 Correct 4 ms 748 KB Output is correct
25 Correct 3 ms 748 KB Output is correct
26 Correct 6 ms 1256 KB Output is correct
27 Correct 6 ms 1260 KB Output is correct
28 Correct 32 ms 4832 KB Output is correct
29 Correct 32 ms 5088 KB Output is correct
30 Correct 73 ms 9948 KB Output is correct
31 Correct 62 ms 8796 KB Output is correct
32 Correct 61 ms 8924 KB Output is correct
33 Correct 56 ms 8668 KB Output is correct
34 Correct 65 ms 8668 KB Output is correct
35 Correct 72 ms 9180 KB Output is correct
36 Correct 60 ms 9564 KB Output is correct