답안 #1050097

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1050097 2024-08-09T07:20:44 Z vjudge1 Art Exhibition (JOI18_art) C++17
50 / 100
1000 ms 40308 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;

class SegmentTree {
public:
    SegmentTree(int size):size(size) {
        tree.resize(4*size,LLONG_MIN);
    }
    
    void build(const vector<long long>& data,int node,int start,int end) {
        if (start==end) {
            tree[node]=data[start];
        } else {
            int mid=(start+end)/2;
            build(data,2*node+1,start,mid);
            build(data,2*node+2,mid+1,end);
            tree[node]=max(tree[2*node+1],tree[2*node+2]);
        }
    }
    
    void update(int idx,long long value,int node,int start,int end) {
        if (start==end) {
            tree[node]=value;
        } else {
            int mid=(start+end)/2;
            if (start<=idx && idx<=mid) {
                update(idx,value,2*node+1,start,mid);
            } else {
                update(idx,value,2*node+2,mid+1,end);
            }
            tree[node]=max(tree[2*node+1],tree[2*node+2]);
        }
    }
    
    long long query(int l,int r,int node,int start,int end) {
        if (r<start || l>end) return LLONG_MIN;
        if (l<=start && end<=r) return tree[node];
        int mid=(start+end)/2;
        return max(query(l,r,2*node+1,start,mid),query(l,r,2*node+2,mid+1,end));
    }
    
private:
    vector<long long> tree;
    int size;
};

int main() {
    long long n;
    cin>>n;
    
    vector<pair<long long,long long>> art(n);
    vector<long long> values(n);
    
    for (long long i=0;i<n;++i) {
        cin>>art[i].first>>art[i].second;
        values[i]=art[i].second;
    }
    
    sort(art.begin(),art.end());
    
    SegmentTree segmentTree(n);
    segmentTree.build(values,0,0,n-1);
    
    long long ans=LLONG_MIN;
    
    for (int left=0;left<n;++left) {
        long long sum=0;
        long long min_size=art[left].first;
        
        for (int right=left;right<n;++right) {
            sum+=art[right].second;
            long long max_size=art[right].first;
            long long current_value=sum-(max_size-min_size);
            ans=max(ans,current_value);
        }
    }

    cout<<ans<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 440 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 440 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 440 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 440 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 11 ms 600 KB Output is correct
28 Correct 11 ms 860 KB Output is correct
29 Correct 11 ms 852 KB Output is correct
30 Correct 11 ms 848 KB Output is correct
31 Correct 10 ms 604 KB Output is correct
32 Correct 10 ms 660 KB Output is correct
33 Correct 18 ms 856 KB Output is correct
34 Correct 18 ms 680 KB Output is correct
35 Correct 10 ms 604 KB Output is correct
36 Correct 18 ms 844 KB Output is correct
37 Correct 11 ms 604 KB Output is correct
38 Correct 10 ms 604 KB Output is correct
39 Correct 10 ms 852 KB Output is correct
40 Correct 10 ms 600 KB Output is correct
41 Correct 10 ms 604 KB Output is correct
42 Correct 10 ms 680 KB Output is correct
43 Correct 11 ms 860 KB Output is correct
44 Correct 10 ms 668 KB Output is correct
45 Correct 18 ms 604 KB Output is correct
46 Correct 11 ms 856 KB Output is correct
47 Correct 10 ms 660 KB Output is correct
48 Correct 10 ms 848 KB Output is correct
49 Correct 11 ms 700 KB Output is correct
50 Correct 11 ms 604 KB Output is correct
51 Correct 10 ms 616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 440 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 440 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 11 ms 600 KB Output is correct
28 Correct 11 ms 860 KB Output is correct
29 Correct 11 ms 852 KB Output is correct
30 Correct 11 ms 848 KB Output is correct
31 Correct 10 ms 604 KB Output is correct
32 Correct 10 ms 660 KB Output is correct
33 Correct 18 ms 856 KB Output is correct
34 Correct 18 ms 680 KB Output is correct
35 Correct 10 ms 604 KB Output is correct
36 Correct 18 ms 844 KB Output is correct
37 Correct 11 ms 604 KB Output is correct
38 Correct 10 ms 604 KB Output is correct
39 Correct 10 ms 852 KB Output is correct
40 Correct 10 ms 600 KB Output is correct
41 Correct 10 ms 604 KB Output is correct
42 Correct 10 ms 680 KB Output is correct
43 Correct 11 ms 860 KB Output is correct
44 Correct 10 ms 668 KB Output is correct
45 Correct 18 ms 604 KB Output is correct
46 Correct 11 ms 856 KB Output is correct
47 Correct 10 ms 660 KB Output is correct
48 Correct 10 ms 848 KB Output is correct
49 Correct 11 ms 700 KB Output is correct
50 Correct 11 ms 604 KB Output is correct
51 Correct 10 ms 616 KB Output is correct
52 Execution timed out 1075 ms 40308 KB Time limit exceeded
53 Halted 0 ms 0 KB -