• Source
    1. #include<bits/stdc++.h>
    2.  
    3. using namespace std;
    4.  
    5. int main()
    6. {
    7. int m,n,t,res,store,mn_beer_time,mn,mx,res_mx;
    8.  
    9. while(scanf("%d%d%d",&m,&n,&t)!=EOF)
    10. {
    11. if(m==1 || n==1)
    12. {
    13. printf("%d\n",t);
    14.  
    15. continue;
    16. }
    17.  
    18. (m>n) ? store=m,m=n,n=store : m=m,n=n;
    19.  
    20. res_mx = t/m;
    21.  
    22. if(t%m==0)
    23. {
    24. printf("%d\n",res_mx);
    25. }
    26. else
    27. {
    28. mn_beer_time = t%m;
    29.  
    30. int len = t/n;
    31.  
    32. for(res=1; res<=len ; res++)
    33. {
    34. mx = (t-(res*n))/m + res;
    35.  
    36. mn = t-(((mx-res)*m)+(res*n));
    37.  
    38. if(mn<mn_beer_time && mn>=0)
    39. {
    40. mn_beer_time = mn;
    41.  
    42. res_mx = mx;
    43. }
    44.  
    45. if(mn==0)
    46. {
    47. break;
    48. }
    49. }
    50.  
    51. if(mn_beer_time==0)
    52. {
    53. printf("%d\n",mx);
    54. }
    55. else
    56. {
    57. printf("%d %d\n",res_mx,mn_beer_time);
    58. }
    59. }
    60. }
    61.  
    62. return 0;
    63. }