# Google Kickstart 2020 Round B problem B

Im not able to understand where Im going wrong. Im modifying the elements from last so that the the day can be delayed as much as possible.

My code:

#include<bits/stdc++.h>

#define ll long long int

#define ff(i,a,b) for(ll i = a; i < b; i++)

#define bf(i,b,a) for(ll i = b-1; i >= 0; i–)

#define itf(i,a) for(auto i = a.begin(); i != a.end(); i++)

#define MII map<int,int>

#define VI vector

#define VC vector

#define VS vector

#define PB push_back

#define F first

#define S second

#define tc ll t; cin>>t; while(t–)

#define DISPV(v) itf(i,v) cout << *i << " ";

#define DISPM(m) itf(i,m) cout << i->F << ’ ’ << i->S << endl;

const int MOD = int(1e9) + 7;

using namespace std;

ll modif(ll a, ll d){

``````if(d%a == 0)

return d;

else{

ll t = floor(d/a);

return t*a;

}
``````

}

int solve(){

``````ll n, d;

cin >> n >> d;

ll a;

VI v;

ll A[n];

ff(i,0,n){

cin >> A[i];

}

for(ll i = n-1; i >= 0; i--){

if(i == n-1)

A[i] = modif(A[i], d);

else

A[i] = modif(A[i], A[i+1]);

}

ff(i,0,n)

cout << A[i] << " " ;

cout << endl;

// sort(A,A+n);

return A[0];
``````

}

int main() {

``````ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

ll t;

cin >> t;

for(ll i = 1; i <= t; i++){

cout << "Case #" << i << ": " << solve() << '\n';

}
``````

}

probliem is in the function modif.
Instead of dividing by a and again multiplying a, what you should do is subtracting d%a from d and returning d.

for(int i=n-1;i>=0;i–) {
if(d%arr[i] !=0) {
d = d - (d%arr[i]);
}
}
System.out.println(“Case #” +ts+": " +d);

This is what i did.

1 Like