2 solutions

  • -1
    @ 2025-7-3 10:49:01
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    	int x,y,z;
    	cin>>x>>y>>z;
    	if(y<0) 
    	{
    		x=-x;
    		y=-y;
    		z=-z;
    	}
    	if(x<y)
    	{
    		cout<<abs(x);
    	}
    	else
    	{
    		if(z>y)
    		{
    			cout<<-1;
    		}
    		else
    		{
    			cout<<abs(z)+abs(x-z); 
    		}
    	}
    	return 0;
    }
    
    • -1
      @ 2025-4-18 18:42:56
      #include<bits/stdc++.h>
      using namespace std;
      int main()
      {
      	int x,y,z;
      	cin>>x>>y>>z;
      	if(y<0) 
      	{
      		x=-x;
      		y=-y;
      		z=-z;
      	}
      	if(x<y)
      	{
      		cout<<abs(x);
      	}
      	else
      	{
      		if(z>y)
      		{
      			cout<<-1;
      		}
      		else
      		{
      			cout<<abs(z)+abs(x-z); 
      		}
      	}
      	return 0;
      }
      
      
      • 1

      Information

      ID
      2365
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      3
      Tags
      (None)
      # Submissions
      73
      Accepted
      25
      Uploaded By