Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions Searching and sorting applications/Momos market.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,87 @@
*/

Name: Bhavya Tyagi
Thapar Institute of Engineering & Technology, Patiala


PROBLEM STATEMENT
Shreya loves to eat momos. Her mother gives her money to buy vegetables but she
manages to save some money out of it daily. After buying vegetables, she goes to
"Momos Market", where there are ‘n’ number of shops of momos. Each of the shop of
momos has a rate per momo. She visits the market and starts buying momos (one from
each shop) starting from the first shop. She will visit the market for ‘q’ days.
You have to tell that how many momos she can buy at each day if she starts buying
from the first shop daily. She cannot use the remaining money of one day on some other
day. But she will save them for other expenses in future, so,
you also need to tell the sum of money left with her at the end of each day.
*/

//This Code gives TLE for only 1 test case

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

void momos(vector<ll> a,ll n,vector<ll> b,ll q)
{
ll p=q,j=0;
while(p--&&j<q)
{
ll moneyForDay=b[j],moneyLeft,count=0;
for(ll i=0;i<n;i++)
{
if(moneyForDay<a[i])
{

moneyLeft=moneyForDay;
break;
}
moneyForDay=moneyForDay-a[i];
count++;
}
cout<<count<<" "<<moneyLeft<<endl;;
j++;
}
}
int main()
{
ll n;
vector<ll> a,b;
cin>>n;
ll m=n;
while(m--)
{
ll input;
cin>>input;
a.push_back(input);
}
ll q;
cin>>q;
ll p=q;
while(p--)
{
ll days;
cin>>days;
b.push_back(days);
}

momos(a,n,b,q);
return 0;
}













//Code By the Original Author - Time-Limit-Exceeded for 3 testcases
/*

Name: Mehul Chaturvedi
Expand Down