Greedy Puppy

i don’t know whats wrong with my code ???
it do pass the test cases …(thanks in advance)

    #include <iostream>
    #include <algorithm>
    using namespace std;
    long long int greed(long long int n,long long int k){
    long long int maxi=0;
    for(long long int i=1;i<=k;i++){
    maxi=(maxi,n%k);  
    }
    return maxi;
    }

    int main() {
// your code goes here
int n;
cin>>n;

while(n--){
    long long int n,k;
    cin>>n>>k;
    cout<<greed(n,k)<<endl;
}


return 0;
   }

try using #include in the starting of the program

1 Like

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

Link to Problem: Contest Page | CodeChef

2 Likes

i did it
Now can you please tell me ??

Instead of this
maxi=(maxi,n%k);

THIS should come

maxi = max(maxi,n%i)

2 Likes

:smiling_face_with_three_hearts: Thanks a lot !!