summaryrefslogtreecommitdiff
path: root/lonesome/lonesome.cpp
blob: 8c13b1168f4860b184c7abf651de65fd6c5d0fa7 (plain)
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
#include <iostream>
using namespace std;

int main()
{
    int dur;
    cin>>dur;
    while(dur>0)
    {
	int deprecs, months, depmonth, i;
	double dwp, amt, val, cur_depval, iments, deps[100]={0.0};
	bool nend;
	
	cin>>dwp>>amt>>deprecs;
	for(i=0;i<deprecs;i++)
	    cin>>depmonth>>deps[depmonth];

	val = dwp+amt;
	iments = amt/dur;
	nend = true;
	
	for(months=0; ; ++months)
	{
	    if(deps[months]>0)
		cur_depval=deps[months];
	    val -= val*cur_depval;
	    if(val>amt)
		break;
	    amt -= iments;
	}
	if(months==1)
	    cout<<months<<" month\n";
	else
	    cout<<months<<" months\n";
	cin>>dur;
    }
    return 0;
}