QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#499398#6727. K-hour ClockbuzhijingdiWA 0ms3620kbC++14740b2024-07-31 13:52:212024-07-31 13:52:22

Judging History

你现在查看的是最新测评结果

  • [2024-07-31 13:52:22]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3620kb
  • [2024-07-31 13:52:21]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

int x, y, z;
int check(int k)
{
	if ((x + (y % k)) % k > z) {
		return 1;
	}
	else if((x + (y % k)) % k < z){
		return 2;
	}
	else {
		return 0;
	}
}

void solve()
{
	
	cin >> x >> y >> z;
	if (x + y < z) {
		cout << -1<<endl;
		return;
	}
	if (x + y == z) {
		cout << x + y + 1<<endl;
		return;
	}
	long long l = x; long long r = x + y;
	long long mid;
	while (l<r)
	{
		mid = (l + r)/2;
		//cout << "mid " << mid << endl;
		if (check(mid)==1) {
			l = mid + 1;
		}
		else if(check(mid)==2){
			r = mid - 1;
		}
		else {
			break;
		}
	}
	cout << l<<endl;
}

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3620kb

input:

4
11 18 5
3 49 4
1 9 1
1 3 10

output:

24
48
1
-1

result:

wrong answer Case #3: k <= x (x = 1, y = 9, z = 1, k = 1)