matbensch

NAQ22 L Solution (C++)

Feb 4th, 2023
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int a,b,c;
  8.     cin>>a>>b>>c;
  9.  
  10.     int ans = 1e9;
  11.  
  12.     for(int i=1;i<=4;i++) for(int j=1;j<=4;j++)
  13.     {
  14.         int s = a;
  15.        
  16.         if(i==4) if(s%b==0) s/= b; else continue;
  17.         else if(i==3) s*=b;
  18.         else if(i==2) s-=b;
  19.         else if(i==1) s+=b;
  20.  
  21.         if(j==4) if(s%c==0) s/= c; else continue;
  22.         else if(j==3) s*=c;
  23.         else if(j==2) s-=c;
  24.         else if(j==1) s+=c;
  25.  
  26.         if(s>=0) ans = min(ans,s);
  27.     }
  28.  
  29.     cout << ans << '\n';
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment