Submission #203295

# Submission time Handle Problem Language Result Execution time Memory
203295 2020-02-20T07:01:46 Z wendy_virgo Art Exhibition (JOI18_art) C++14
0 / 100
5 ms 376 KB
#include <bits/stdc++.h>

using namespace std;

#define taskname "JOI18_art"
#define forinc(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define fordec(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define foreach(i, x) for (auto &i : x)
#define ms(x, n) memset(x, n, sizeof(x))
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define fi first
#define se second
#define pb push_back
#define pf push_front

template<typename TH>
void _dbg(const char* sdbg, TH h)
{
	cerr << sdbg << " = " << h << "\n";
}

template<typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t)
{
	while (*sdbg != ',') cerr << *sdbg++;
	cerr << " = " << h << ",";
	_dbg(sdbg + 1, t...);
}

#define db(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define chkpt cerr << "--- Checkpoint here ---\n";

const int N=5e5+5;

int n;
int64_t a[N],b[N],aOri[N];
int p[N],l[N],r[N];
int64_t s[N];

bool Cmp(int x,int y)
{
    return a[x]<a[y];
}

void Sub3()
{
    int64_t ans=0;
    forinc(i,1,n)
    {
        p[i]=i;
    }
    sort(p+1,p+1+n,Cmp);
    vector<int> zip;
    forinc(i,1,n)
    {
        zip.pb(a[i]);
    }
    sort(all(zip));
    uni(zip);
    forinc(i,1,n)
    {
        aOri[i]=a[i];
        a[i]=lower_bound(all(zip),a[i])-zip.begin()+1;
    }
    forinc(i,1,n)
    {
        r[a[p[i]]]=i;
        s[i]=s[i-1]+b[p[i]];
    }
    fordec(i,n,1)
    {
        l[a[p[i]]]=i;
    }
    forinc(i,1,n)
    {
        forinc(j,i,n)
        {
            ans=max(ans,s[r[a[p[j]]]]-s[l[a[p[i]]]-1]-aOri[p[j]]+aOri[p[i]]);
        }
    }
    cout<<ans;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifndef ONLINE_JUDGE
//	freopen(taskname".INP","r",stdin);
	#endif // ONLINE_JUDGE
	cin>>n;
	forinc(i,1,n)
	{
	    cin>>a[i]>>b[i];
	}
	Sub3();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -