답안 #1107812

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1107812 2024-11-02T07:05:48 Z vjudge1 Art Exhibition (JOI18_art) C++17
0 / 100
191 ms 262144 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;
      |         ^~~
art.cpp:18:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |    freopen("input.txt", "r", stdin);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
art.cpp:19:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |    freopen("output.txt", "w", stdout);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 191 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 191 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 191 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 191 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -