-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10114.cpp
110 lines (108 loc) · 3.75 KB
/
10114.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<stack>
using namespace std;
int i,month,res,dep,j,konmnth,k;
double charge,cartaka,owes,percen,past;
int main(){
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
while(scanf("%d %lf %lf %d",&month,&charge,&cartaka,&dep)!=EOF){
if(month<0)break;
j=0;
res=0;
past=0;
owes=0;
int flag=0;
double c=charge;
charge=cartaka/(double)month;
owes=cartaka;
cartaka=cartaka+c;
//printf("mote cartaka=%lf owes=%lf\n",cartaka,owes);
for(i=0;i<dep;i++){
scanf("%d %lf",&konmnth,&percen);
if(konmnth==0){
past=percen;
j=konmnth;
cartaka=cartaka-(cartaka*percen);
//printf("ekhon 2222 cartaka %lf owes %lf month %d\n",cartaka,owes,res);
if(owes<cartaka && flag==0){
flag=1;
printf("0 months\n");
}
//printf("ekhon 0000 cartaka %lf owes %lf month %d\n",cartaka,owes,res);
}
else{
if(konmnth-j==1){
res++;
cartaka=cartaka-(cartaka*percen);
owes=owes-charge;
// printf("ekhon 2222 cartaka %lf owes %lf month %d\n",cartaka,owes,res);
if(owes<cartaka && flag==0){
if(res==1){
flag=1;
printf("%d month\n",res);
break;
}
else{
flag=1;
printf("%d months\n",res);
}
}
past=percen;
j=konmnth;
//printf("ekhon cartaka %lf owes %lf month %d\n",cartaka,owes,res);
}
else{
j=j+1;
//printf("j holo %d rrrr past holo %lf\n",j,past);
for(k=j;k<=konmnth;k++){
res++;
if(k==konmnth)past=percen;
cartaka=cartaka-(cartaka*past);
owes=owes-charge;
//printf("ekhon 2222 cartaka %lf owes %lf month %d\n",cartaka,owes,res);
if(owes<cartaka && flag==0){
//printf("EIKHANE DHUKSE\n");
if(res==1){
//printf("eikhane dhukse");
printf("%d month\n",res);
flag=1;
}
else{
flag=1;
printf("%d months\n",res);
}
}
}
j=konmnth;
}
}
}
if(flag==0){
j=j+1;
//printf("eikhane dhukse past=%lf\n j=%d\n",past,j);
for(i=j;i<=month;i++){
res++;
cartaka=cartaka-(cartaka*past);
owes=owes-charge;
if(owes<cartaka){
if(res==1){
//printf("eikhane dhukse");
printf("%d month\n",res);
break;
}
else{
printf("%d months\n",res);
break;
}
}
}
}
}
}