Submission #1081869

# Submission time Handle Problem Language Result Execution time Memory
1081869 2024-08-30T12:21:40 Z lamlamlam Art Exhibition (JOI18_art) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int MN = 5e5+5;
int n;
__int128 pre[MN],suf[MN],ans,tmp;
pair<int,int> a[MN];
void print(__int128 x)
{
    string res = "";
    if(x==0) {
        cout << 0;
        return;
    }
    if(x<0) res += '-', x = -x;
    while(x!=0){
        res += '0' + x%10;
        x /= 10;
    }
    for(int i=res.size(); i>=0; i--) cout << res[i];
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #define task "troll"
    if(fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    cin >> n;
    for(int i=1; i<=n; i++) cin >> a[i].first >> a[i].second;
    sort(a+1,a+1+n);
    for(int i=2; i<=n; i++) pre[i] = a[i].second - (a[i].first-a[i-1].first);
    for(int i=2; i<=n; i++) pre[i] += pre[i-1];
    //for(int i=1; i<=n; i++) print(pre[i]), cout << endl;
    suf[n+1] = -1e36;
    for(int i=n; i>1; i--) suf[i] = max(suf[i+1],pre[i]);
    //for(int i=1; i<=n; i++) print(suf[i]), cout << endl;
    ans = a[n].second;
    for(int i=1; i<n; i++) {
        tmp = a[i].second;
        ans = max({ans,tmp+suf[i+1]-pre[i],tmp});
    }
    print(ans);
    cerr << "\nTime: " << 1000.0 * clock() / CLOCKS_PER_SEC << endl;
}

Compilation message

art.cpp: In function 'int main()':
art.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
art.cpp:31:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -