Submission #335934

# Submission time Handle Problem Language Result Execution time Memory
335934 2020-12-14T10:34:31 Z Killer2501 Split the sequence (APIO14_sequence) C++14
0 / 100
16 ms 2816 KB
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pll pair<ll, ll>
#define pb push_back
#define pii pair<ll ,pll>
#define task "C"

using namespace std;
const int N = 3e5+5;
const int mod = 1e9+7;
ll n, t, m, k, a[N], b[N], ans, tong, u, v;
string s;
bool ok;

pll p[N];
struct dang
{
    ll x, y, id;
    dang(){}
    dang(ll x, ll y, ll id): x(x), y(y), id(id){}
};
bool cmp(const dang& u, const dang& v)
{
    return ((u.x < v.x) || (u.x == v.x && u.y < v.y));
}

void sol()
{
    cin >> n;
    for(int i = 1; i <= n; i ++)
    {
        cin >> p[i].fi >> p[i].se;
    }
    sort(p+1, p+1+n);
    ans = p[1].se;
    a[1] = p[1].se;
    k = -p[1].fi;
    for(int i = 2; i <= n; i ++)
    {
        a[i] = a[i-1] + p[i].se;
        ans = max(p[i].se, max(ans, a[i] - p[i].fi - k));
        //cout << a[i] - p[i].fi <<" "<<k<<'\n';
        k = min(k, a[i-1] - p[i].fi);
    }
    cout << ans;

}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(fopen(task".inp", "r"))
    {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   57 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:58:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   58 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 620 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 2816 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -