#include
using namespace std; #define ll long long
int main(){
int tc;
cin>>tc;
while(tc–){
ll n,r;//r is relax per minute,and n is count of minutes.
cin>>n>>r;
ll A[n];//array representing time
for(ll i=1;i<=n;i++){
cin>>A[i];
}
ll B[n];//array representing tension at any time
for(ll i=1;i<=n;i++){
cin>>B[i];
}
ll tension[n],max=0;//we define array tension that depicts tension at every A[i].
if(n==1){
max=B[1];
}
else{tension[1]=B[1];
for(ll i=2;i<=n;i++){
tension[i]=tension[i-1]-((A[i]-A[i-1])*r)+B[i];//tension at any point is tensionat previous point minus relax tension and add tension given at that moment i.e B[i]
if(tension[i]>=max){// i am finding out the max element among tension array and that would be our answer
max=tension[i];
}}}
cout<<max<<endl;
}
}
plz tell me why compiler is giving wrong answer instead of passing examples succesfully
I think max_t should be placed above the if statement because if we place below the if statement then we wont consider the case for the first time when he is doing the exercise. Hope you understood it.
#include <bits/stdc++.h> #define ll unsigned long long
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--)
{
ll int N, relief;
cin >> N >> relief;
vector<ll int> times(N);
for (ll int i = 0; i < N; i++)
cin >> times[i];
vector<ll int> tension(N);
for (ll int i = 0; i < N; i++)
cin >> tension[i];
if (N == 1)
{
cout << tension[0] << endl;
}
else
{
ll int T = tension[0];
for (ll int i = 1; i < N; i++)
{
T = T - relief + tension[i];
}
cout << T << endl;
}
}
return 0;
#include<bits/stdc++.h>
using namespace std;
long long int max(long long int a,long long int b)
{
if(a>=b)
return a;
else
return b;
}
int main()
{
int i,t;
cin>>t;
for(i=0;i<t;i++)
{
long long q=0;
long n,j,r,k;
cin>>n>>r;
vector<long long> a(n), b(n),ans(n);
for(j=0;j<n;j++)
{
cin>>a[j];
}
for(j=0;j<n;j++)
{
cin>>b[j];
}
for(j=0;j<n;j++)
{
k=(a[j+1]-a[j])*r;
q+=b[j]-max(k,0);
ans[j]=q;
}
sort(ans.begin(),ans.end());
cout<<ans[n-1];
q=0;
cout<<'\n';
}
return 0;
}
#include
using namespace std;
int main()
{ int t;
cin>>t;
while(t>0)
{
long long int n,r,i,x=0,y=0,ans;
cin>>n>>r;
long long int a[n],b[n];
for(i=1;i<=n;i++)
{
cin>>a[i];
}
for(i=1;i<=n;i++)
{
cin>>b[i];
}
while (t–)
{
ll int N, relief;
cin >> N >> relief;
vector<ll int> times(N);
for (ll int i = 0; i < N; i++)
cin >> times[i];
vector<ll int> tension(N);
for (ll int i = 0; i < N; i++)
cin >> tension[i];
if (N == 1)
{
cout << tension[0] << endl;
}
else
{
ll int T = tension[0];
for (ll int i = 1; i < N; i++)
{
// You are calculating tension -> by including subtraction of relief and
// addition of tension in next exercise which is wrong.
T = T - relief + tension[i];
// Instead of this as mentioned in the Q that before any workouts, relief =0.
// so in above statement if (T - relief ) < 0 then T should be considered as
// zero before adding another exercise tension to it.
// and relief is not alone to be considered as relief it must be ->
// relief (times[i] - times[i-1])
/* T = T - relief (times[i] - times[i-1]) ;
if(T < 0)
T = 0;
T = T + tension[i]; */
}
cout << T << endl;
}