fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int K = 0, T = 0, a = 0, dV = 1;
  6. cin >> K >> T;
  7. while (T > 0) {
  8. a+=dV;
  9. if(a == K || K == 0){
  10. dV = -dV;
  11. }
  12. T--;
  13. }
  14. cout << a;
  15. return 0;
  16. }
Success #stdin #stdout 0s 4304KB
stdin
12
23
stdout
1