답안 #1107815

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1107815 2024-11-02T07:07:34 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=0;
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>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:38:9: warning: unused variable 'pos' [-Wunused-variable]
   38 |     int pos=1;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2384 KB Output isn't correct
2 Halted 0 ms 0 KB -