-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathP10114.cpp
More file actions
30 lines (30 loc) · 795 Bytes
/
P10114.cpp
File metadata and controls
30 lines (30 loc) · 795 Bytes
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
int main() {
int duration, depreciationRecords;
double downPayment, loanAmount, depreciation[101];
while(true) {
cin >> duration >> downPayment >> loanAmount >> depreciationRecords;
if(duration < 0)
return 0;
memset(depreciation, -1, 101*sizeof(double));
FORI(depreciationRecords) {
int idx;
cin >> idx;
cin >> depreciation[idx];
}
double dep = depreciation[0];
double value = (downPayment + loanAmount)*(1-dep);
double owed = loanAmount;
int ret = 0;
while(owed >= value) {
++ret;
if(depreciation[ret] >= 0)
dep = depreciation[ret];
value *= (1-dep);
owed = loanAmount * (duration-ret)/(double)duration;
}
cout << ret << " month";
if(ret != 1)
cout << "s";
cout << endl;
}
}