結果

問題 No.1440 The Quiz Competition
ユーザー kotatsugame
提出日時 2021-03-27 01:41:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 844 bytes
コンパイル時間 440 ms
コンパイル使用メモリ 65,120 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-29 05:13:32
合計ジャッジ時間 1,274 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 12 WA * 15
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:4:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    4 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
int T;
main()
{
	cin>>T;
	for(;T--;)
	{
		int N,A,W,K;
		cin>>N>>A>>W>>K;
		if(A<K-1&&N-K+1>W)
		{
			cout<<":("<<endl;
		}
		else if(N>K)
		{
			if(K-1<=A)
			{
				cout<<(A-(K-1))/K<<endl;
			}
			else//if(N-K+1<=W)
			{
				cout<<-1<<endl;
			}
		}
		else
		{
			if(W%N==0)
			{
				if(A>=N-1)
				{
					long S=0;
					long T=W/N;
					S-=T*(T+1)/2;
					if(A>=N-1)S+=(A-(N-1))/N;
					cout<<S<<endl;
				}
				else//if(W>0)
				{
					long S=0;
					long T=W/N-1;
					S-=T*(T+1)/2;
					S-=T+1;
					cout<<S<<endl;
				}
			}
			else
			{
				int n=W%N;
				long S=0;
				long T=W/N;
				S-=T*(T+1)/2;
				T++;
				S-=T;
				if(n-1<=A)
				{
					A-=n-1;
					int a=A/n;
					if(a<T)S+=a;
					else
					{
						S+=T-1;
						A-=(T-1)*n;
						S+=A/N;
					}
				}
				cout<<S<<endl;
			}
		}
	}
}
0