-
Notifications
You must be signed in to change notification settings - Fork 0
/
D.cpp
60 lines (60 loc) · 1.11 KB
/
D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n,i,ara[85],d[85],sum=1000,c=0,count=0;
cin>>n;
for(i=0;i<n;i++)
cin>>ara[i];
sum=1000;
for(i=0;i<n;i++)
{
if(i==0)
{
d[count]=ara[i];
count++;
}
else if(ara[i]!=ara[i-1])
{
d[count]=ara[i];
count++;
}
}
for(i=0;i<count;i++)
{
if(i==0)
{
if(d[i]<d[i+1])
{
c=c+sum/d[i];
sum=sum%d[i];
}
}
else if(i==count-1)
{
if(c>0)
{
sum=sum+c*d[i];
c=0;
}
}
else
{
if(d[i]<d[i-1] && d[i]<d[i+1])
{
c=c+sum/d[i];
sum=sum%d[i];
}
else if(d[i]>d[i-1] && d[i]>d[i+1])
{
if(c>0)
{
sum=sum+c*d[i];
c=0;
}
}
}
}
cout<<sum<<endl;
return 0;
}