#include<bits/stdc++.h>
using namespace std;
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define PI acos(-1.0)
#define MOD 1000000007
#define MX 100010
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
double tmonth, downPay, price, interest[105], owe;
int k, m;
while(cin>>tmonth>>downPay>>price>>k && tmonth>=0)
{
owe=price;
double monthlyPay=price/(double) tmonth;
price+=downPay;
for(int i=0;i<=tmonth;i++) interest[i]=-1;
for(int i=0;i<k;i++)
{
cin>>m;
cin>>interest[m];
}
for(int i=1;i<=tmonth;i++)
if(interest[i]==-1) interest[i]=interest[i-1];
int ans=-1;
int i=0;
while(ans==-1)
{
price=price-price*interest[i];
if(price>owe) ans=i;
owe-=monthlyPay;
i++;
}
cout<<ans<<" month";
if(ans!=1) cout<<"s";
cout<<"\n";
}
return 0;
}
No comments:
Post a Comment