#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
typedef pair <ll,ll> ii;
ll l;
ll r;
ll m;
int n;
vector <ll> x;
vector <ll> g;
vector <ll> d;
vector <ll> real_d;
vector <ll> best;
bool flag;
ll ptr1,ptr2;
ll cost;
ll gold;
ll electric;
ll xptr2;
int main()
{
scanf("%d",&n);
best=vector <ll> (n+1);
g.pb(0);
d.pb(0);
for(int i=0;i<n;i++)
{
ll a,b,c;
scanf(" %lld %lld %lld",&a,&b,&c);
x.pb(a);
g.pb(b);
g[g.size()-1]+=g[g.size()-2];
d.pb(c);
d[d.size()-1]+=d[d.size()-2];
real_d.pb(c);
}
ptr1=n-1;
ptr2=n;
while(1)
{
if(ptr1<1)
{
for(int i=ptr1+1;i<=ptr2;i++)
{
best[i]=ptr2;
}
break;
}
cost=x[ptr2-1]-x[ptr1];
electric=d[ptr2]-d[ptr1];
if(ptr1==2)
{
//printf("\n%lld %lld\n\n",cost,electric);
}
if(electric>=cost)
{
ptr1--;
}
else
{
for(int i=ptr1+2;i<=ptr2;i++)
{
best[i]=ptr2;
}
ptr2=ptr1+1;
}
}
/*for(int i=1;i<=n;i++)
{
printf("%lld ",best[i]);
}
printf("\n");*/
l=0;
r=100000000000000007;
m=(l+r+1)/2;
while(l!=r)
{
//if(m<100)\
printf("%lld %lld %lld\n",l,m,r);
flag=0;
ptr1=0,ptr2=1;
while(1)
{
xptr2=best[ptr2];
cost=x[xptr2-1]-x[ptr1];
gold=g[xptr2]-g[ptr1];
electric=d[xptr2]-d[ptr1];
//if(m<100)\
printf("%lld %lld %lld %lld %lld\n",ptr1,ptr2,cost,gold,electric);
if(gold<m)
{
if(ptr2>=n)
{
break;
}
ptr2++;
}
else
{
if(electric>=cost)
{
flag=1;
break;
}
ptr1++;
}
}
if(flag)
{
l=m;
}
else
{
r=m-1;
}
m=(l+r+1)/2;
}
printf("%lld\n",m);
}
Compilation message
divide.cpp:112:9: warning: multi-line comment [-Wcomment]
112 | //if(m<100)\
| ^
divide.cpp:127:13: warning: multi-line comment [-Wcomment]
127 | //if(m<100)\
| ^
divide.cpp: In function 'int main()':
divide.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
divide.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | scanf(" %lld %lld %lld",&a,&b,&c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
4 ms |
596 KB |
Output is correct |
24 |
Correct |
5 ms |
660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
4 ms |
596 KB |
Output is correct |
24 |
Correct |
5 ms |
660 KB |
Output is correct |
25 |
Correct |
3 ms |
596 KB |
Output is correct |
26 |
Correct |
4 ms |
980 KB |
Output is correct |
27 |
Correct |
5 ms |
980 KB |
Output is correct |
28 |
Correct |
22 ms |
2364 KB |
Output is correct |
29 |
Correct |
21 ms |
2364 KB |
Output is correct |
30 |
Correct |
42 ms |
4324 KB |
Output is correct |
31 |
Correct |
49 ms |
4372 KB |
Output is correct |
32 |
Correct |
39 ms |
4232 KB |
Output is correct |
33 |
Correct |
40 ms |
4232 KB |
Output is correct |
34 |
Correct |
65 ms |
4268 KB |
Output is correct |
35 |
Correct |
76 ms |
4360 KB |
Output is correct |
36 |
Correct |
84 ms |
4268 KB |
Output is correct |