Submission #1107814

# Submission time Handle Problem Language Result Execution time Memory
1107814 2024-11-02T07:06:49 Z vjudge1 Art Exhibition (JOI18_art) C++17
0 / 100
1 ms 2384 KB
#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
using namespace std;
const int N=5e5+5;
const int inf=1e18;
const int mod=1e9+7;
const int N1=1e5+25;
vector<pair<int,int> >v;
vector<int>v1;
int dp[N];
int dp1[N];
struct edge{
    int v,time;
};
signed main(){
//   freopen("input.txt", "r", stdin);
 //  freopen("output.txt", "w", stdout);
    boost;
    int n;
    cin>>n;
    v.push_back({0,0});
    int ans=-inf;
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        ans=max(ans,y);
        v.push_back({x,y});
    }
    sort(v.begin(),v.end());
    int cnt=0;
    for(int i=1;i<=n;i++){
        cnt+=v[i].second;
        dp[i]=cnt-v[i].first;
            dp1[i]=dp1[i-1]+v[i].second;
    }
    cnt=v[1].first;
    int pos=1;
    for(int i=2;i<=n;i++){
        ans=max(ans,dp[i]+cnt);
        if(cnt>dp1[i-1]-v[i].first){
            cnt=dp1[i-1]-v[i].first;
        }
    }
    cout<<ans;
}

Compilation message

art.cpp: In function 'int main()':
art.cpp:39:9: warning: unused variable 'pos' [-Wunused-variable]
   39 |     int pos=1;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Incorrect 1 ms 2384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Incorrect 1 ms 2384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Incorrect 1 ms 2384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Incorrect 1 ms 2384 KB Output isn't correct
3 Halted 0 ms 0 KB -