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 |
#include <iostream> #include <cstdio> #include <fstream> #define INF 100000000 #define ll long long using namespace std; int m,n,MX; int main() { int tt; ll dp; int MN_Rem,MXR; while(scanf("%d%d%d",&m,&n,&tt)!=EOF) { if(m>tt && n>tt) { cout<<0<<" "<<tt<<"\n"; continue; } MX =0; bool f =false; MN_Rem = INF; MXR = 0; for(int i=0;i<=10005;i++) { for(int j=0;j<=10005;j++) { dp =tt-(i*m+j*n); if(i==0 && j==0) continue; if(dp<0)//dp[i][j] break; if(dp==0)//dp[i][j] { if(MX<(i+j)) MX = i+j; f=1; } if(dp>0)//dp[i][j] { if(dp<MN_Rem)//dp[i][j] { MN_Rem = dp;//dp[i][j] MXR = i+j; } else if(dp==MN_Rem)//dp[i][j] { if(MXR<(i+j)) MXR = i+j; } } }//2nd for }//1st for if(f) cout<<MX<<"\n"; else cout<<MXR<<" "<<MN_Rem<<"\n"; } //out.close(); } |