2 条题解

  • 0
    @ 2024-1-7 13:36:10
    #include <iostream>  
    #include <cmath>  
      
    using namespace std;  
      
    int main() {  
        int x, y, k;  
        cin >> x >> y >> k;  
      
        if (x > 0 && y > 0) {  
            if (x >= y) {  
                cout << x << endl;  
            } else if (x + k >= y) {  
                cout << y << endl;  
            } else {  
                cout << 2 * y - x - k << endl;  
            }  
        } else if (x < 0 && y < 0) {  
            if (x <= y) {  
                cout << -x << endl;  
            } else if (x - k <= y) {  
                cout << -y << endl;  
            } else {  
                cout << x - k - 2 * y << endl;  
            }  
        } else {  
            cout << min(2 * abs(y) + abs(x), abs(x) + abs(y) <= k ? 2 * abs(x) + abs(y) : 3 * abs(x) + 2 * abs(y) - k) << endl;  
        }  
        return 0;  
    }
    
    • 0
      @ 2024-1-7 13:32:39
      import java.util.Scanner;
      
      public class Main {
          public static void main(String[] args) {
              Scanner sc = new Scanner(System.in);
              int x = sc.nextInt();
              int y = sc.nextInt();
              int k = sc.nextInt();
              if(x >= y){
                  System.out.println(x);
              }else {
                  if(x + k >= y){
                      System.out.println(y);
                  }else {
                      int d = x + k;
                      System.out.println(d + (y - d) * 2);
                  }
              }
          }
      }
      
      
      • 1

      信息

      ID
      596
      时间
      1000ms
      内存
      256MiB
      难度
      6
      标签
      递交数
      243
      已通过
      69
      上传者