Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 70acb4d

Browse files
Merge pull request #7 from bhavyatyagi/patch-1
This code gives only 1 case as Time-Limit-Exceeded
2 parents 0542f83 + 7d4c3ae commit 70acb4d

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

‎Searching and sorting applications/Momos market.cpp‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,87 @@
1+
*/
2+
3+
Name: Bhavya Tyagi
4+
Thapar Institute of Engineering & Technology, Patiala
5+
6+
7+
PROBLEM STATEMENT
8+
Shreya loves to eat momos. Her mother gives her money to buy vegetables but she
9+
manages to save some money out of it daily. After buying vegetables, she goes to
10+
"Momos Market", where there are ‘n’ number of shops of momos. Each of the shop of
11+
momos has a rate per momo. She visits the market and starts buying momos (one from
12+
each shop) starting from the first shop. She will visit the market for ‘q’ days.
13+
You have to tell that how many momos she can buy at each day if she starts buying
14+
from the first shop daily. She cannot use the remaining money of one day on some other
15+
day. But she will save them for other expenses in future, so,
16+
you also need to tell the sum of money left with her at the end of each day.
17+
*/
18+
19+
//This Code gives TLE for only 1 test case
20+
21+
#include<bits/stdc++.h>
22+
using namespace std;
23+
typedef long long ll;
24+
25+
void momos(vector<ll> a,ll n,vector<ll> b,ll q)
26+
{
27+
ll p=q,j=0;
28+
while(p--&&j<q)
29+
{
30+
ll moneyForDay=b[j],moneyLeft,count=0;
31+
for(ll i=0;i<n;i++)
32+
{
33+
if(moneyForDay<a[i])
34+
{
35+
36+
moneyLeft=moneyForDay;
37+
break;
38+
}
39+
moneyForDay=moneyForDay-a[i];
40+
count++;
41+
}
42+
cout<<count<<" "<<moneyLeft<<endl;;
43+
j++;
44+
}
45+
}
46+
int main()
47+
{
48+
ll n;
49+
vector<ll> a,b;
50+
cin>>n;
51+
ll m=n;
52+
while(m--)
53+
{
54+
ll input;
55+
cin>>input;
56+
a.push_back(input);
57+
}
58+
ll q;
59+
cin>>q;
60+
ll p=q;
61+
while(p--)
62+
{
63+
ll days;
64+
cin>>days;
65+
b.push_back(days);
66+
}
67+
68+
momos(a,n,b,q);
69+
return 0;
70+
}
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+
83+
84+
//Code By the Original Author - Time-Limit-Exceeded for 3 testcases
185
/*
286
387
Name: Mehul Chaturvedi

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /