-
Notifications
You must be signed in to change notification settings - Fork 2
/
buildb.cpp
52 lines (50 loc) · 798 Bytes
/
buildb.cpp
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
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
lli t,z;
cin>>t;
for(z=1;z<=t;z++)
{
lli n,r,x,max=0,k=0;
cin>>n;
cin>>r;
lli a[n];
lli b[n];
for(x=0;x<n;x++)
{
cin>>a[x];
}
for(x=0;x<n;x++)
{
cin>>b[x];
}
max=b[0];
k=b[0];
for(x=1;x<n;x++)
{
k=k-((a[x]-a[x-1])*r);
if(k<0)
{
k=b[x];
}
else
{
k=k+b[x];
}
if(max<=k)
{
max=k;
}
}
cout<<max<<endl;
}
return 0;
}