# PROBLEM LINK: Chef and Ladoos | CodeChef

# Problem Code: Chef and Ladoos | CodeChef

# Practice: CodeChef | Competitive Programming | Participate & Learn | CodeChef

# Contest : Code to Compete Coding Competition | CodeChef

* Author:* Codechef Adgitm Chapter : https://www.codechef.com/users/test_account_9

*Codechef Adgitm Chapter : https://www.codechef.com/users/test_account_9*

**Tester:***Codechef Adgitm Chapter : https://www.codechef.com/users/test_account_9*

**Editorialist:**# DIFFICULTY:

Easy

# PROBLEM:

The chef was a fit guy but recently he has eaten a lot of sweets and the doctor asked him to minimise the consumption of sweets as much as possible. Chef is going in a free ladoo stall, there stalls are established in a grid system, consider it as a Matrix of size m*n, where m represents rows and n columns and each unit represents a new ladoo stall which has a value assigned to represent the amount of ladoos they have.

Your task is to take the chef from the top left corner to the bottom right corner keeping in mind he eats minimum sweets. Chef said he will follow you but on one condition that he will eat all the ladoos of whichever stall we take him to.

# SOLUTION:

C++:

#include <bits/stdc++.h>

using namespace std;

#define ff first

#define ss second

typedef long long ll;

int main(){

```
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
ll a[n][m];
for(ll i=0;i<n;i++){
for(ll j=0;j<m;j++){
cin>>a[i][j];
if(i>0&&j>0){
a[i][j]+=min(a[i-1][j],a[i][j-1]);
}
else if(i>0){
a[i][j]+=a[i-1][j];
}
else if(j>0){
a[i][j]+=a[i][j-1];
}
}
}
cout<<a[n-1][m-1]<<"\n";
}
return 0;
```

}