Submission #247382

# Submission time Handle Problem Language Result Execution time Memory
247382 2020-07-11T09:56:41 Z uacoder123 Divide and conquer (IZhO14_divide) C++14
100 / 100
67 ms 7928 KB
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))

typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int test=1;
  for(;test>0;--test)
  {
    lli n,ans=0;
    cin>>n;
    lli g[n+1]={},arr[n+1]={},arr1[n+1]={},arr2[n+1]={};
    vector<ii> p(n+1);
    p[0]=mp(0,0);
    for(lli i=1;i<=n;++i)
    {
      lli y;
      cin>>arr1[i]>>g[i]>>y;
      p[i].S=i;
      p[i].F=p[i-1].F+y-arr1[i]+arr1[max(i-1,1LL)];
      arr2[i]=arr2[i-1]+y;
      g[i]+=g[i-1];
    }
    sort(p.begin()+1,p.end());
    for(lli i=n;i>=1;--i)
    {
      if(i==n)
        arr[i]=p[i].S;
      else
        arr[i]=max(arr[i+1],p[i].S);
    }
    for(lli i=1;i<=n;++i)
    {
      lli a=-(arr1[i]-arr1[1]-arr2[i-1]);
      auto it=lower_bound(p.begin()+1,p.end(),mp(a,0*1LL))-p.begin();
      if(it!=n+1)
        ans=max(ans,g[arr[it]]-g[i-1]);
    }
    cout<<ans<<endl;
  }
  return(0);
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 432 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 432 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 6 ms 512 KB Output is correct
23 Correct 7 ms 640 KB Output is correct
24 Correct 7 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 432 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 6 ms 512 KB Output is correct
23 Correct 7 ms 640 KB Output is correct
24 Correct 7 ms 640 KB Output is correct
25 Correct 7 ms 640 KB Output is correct
26 Correct 8 ms 896 KB Output is correct
27 Correct 10 ms 1024 KB Output is correct
28 Correct 26 ms 3712 KB Output is correct
29 Correct 31 ms 4088 KB Output is correct
30 Correct 56 ms 7928 KB Output is correct
31 Correct 47 ms 6784 KB Output is correct
32 Correct 45 ms 6912 KB Output is correct
33 Correct 44 ms 6648 KB Output is correct
34 Correct 45 ms 6648 KB Output is correct
35 Correct 59 ms 7160 KB Output is correct
36 Correct 67 ms 7416 KB Output is correct