Submission #1209829

#TimeUsernameProblemLanguageResultExecution timeMemory
1209829nvc2k8Art Exhibition (JOI18_art)C++20
100 / 100
105 ms8336 KiB
#include <bits/stdc++.h>
#define TASK "kasjkasjd"
#define INT_LIM (int) 2147483647
#define LL_LIM (long long) 9223372036854775807
#define endl '\n'
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define BIT(i,x) (((i)>>(x))&1)
#define FOR(i,a,b) for(int i = (a); i<=(b); i++)
#define FORD(i,a,b) for(int i = (a); i>=(b); i--)
#define ll long long
#define pii pair<int,int>
using namespace std;
///------------------------------------------///
int n;
pair<ll,ll> a[500005];

void inp()
{
    cin >> n;
    FOR(i, 1, n) cin >> a[i].fi >> a[i].se;
    sort(a+1, a+1+n);
}

ll maxl = -LL_LIM, ans = 0;

void solve()
{
    ll pre = 0;
    for (int i = 1; i<=n; )
    {
        int nx = n+1;
        ll cursum = 0;

        for (int j = i; j<=n; j++)
        {
            if (a[j].fi!=a[i].fi)
            {
                nx = j;
                break;
            }
            cursum+= a[j].se;
        }

        maxl = max(maxl, a[i].fi-pre);
        ans = max(ans, maxl+pre+cursum-a[i].fi);
        pre+=cursum;

        i = nx;
    }

    cout << ans;
}

signed main()
{
    ///--------------------------///
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    if (fopen(TASK".INP","r")!=NULL)
    {
        freopen(TASK".INP","r",stdin);
        freopen(TASK".OUT","w",stdout);
    }
    ///--------------------------///

    int NTEST = 1;
    //cin >> NTEST;

    while (NTEST--)
    {
        inp();
        solve();
    }

    return 0;
}

///------------------------------------------///

Compilation message (stderr)

art.cpp: In function 'int main()':
art.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen(TASK".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
art.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen(TASK".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...