forked from Sahaj-Bamba/HacktoberTrial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbol.cpp
More file actions
91 lines (90 loc) · 1.35 KB
/
bol.cpp
File metadata and controls
91 lines (90 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include<bits/stdc++.h>
#include<math.h>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define ll long long
#define MOD 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define g 9.8
#define MIN(a,b) (a>b?b:a)
#define par 0.5
using namespace std;
ll n,m,ar[405],s,e,con,tot,max_,ans,str[402][402][2];
ll check(ll);
void findmax();
void bin();
int main()
{
cin>>n>>m;
rep(i,1,n+1)
cin>>ar[i];
rep(i,0,m)
{
cin>>s>>e>>con>>tot;
if(str[s][e][0]==0||(tot<str[s][e][1])||(tot==str[s][e][1]&&con>str[s][e][0]))
{
str[s][e][0]=con;
str[s][e][1]=tot;
}
}
rep(i,1,401)
rep(j,i,401)
{
if(str[i][j][0]!=0)
{
s=i;
e=j;
con=str[i][j][0];
tot=str[i][j][1];
bin();
//cout<<"HERE";
}
}
cout<<ans;
}
ll check(ll mid)
{
ll prev=s;
ll cnt=0;
for(int i=s+1;i<=e;i++)
{
if(ar[i]-ar[prev]>mid)
{
prev=i-1;
cnt++;
}
}
if(cnt>tot)
return 0;
return 1;
}
void findmax()
{
ll prev=s;
max_=0;
for(int i=s+1;i<=e;i++)
{
if(ar[i]-ar[prev]>max_)
max_=ar[i]-ar[prev];
prev=i;
}
}
void bin()
{
findmax();
ll low=max_,high=ar[e]-ar[s],mid;
//if(e-s<=tot)
while(low<=high)
{
mid=(low+high)/2;
if(check(mid))
{
high=mid-1;
max_=mid;
}
else
low=mid+1;
}
//cout<<"HERE "<<max_<<" "<<con<<"\n";
if((max_*con)>ans)
ans=max_*con;
}