結果

問題 No.1440 The Quiz Competition
ユーザー beet
提出日時 2021-03-26 23:21:03
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,327 bytes
コンパイル時間 2,751 ms
コンパイル使用メモリ 191,820 KB
最終ジャッジ日時 2025-01-19 23:34:08
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 6 WA * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=Int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}

//INSERT ABOVE HERE
signed solve(){
  Int n,a,w,k;
  cin>>n>>a>>w>>k;

  if(n==1){
    cout<<a<<newl;
    return 0;
  }

  if(n==k and w>0){
    // cout<<"A"<<newl;
    Int d=w/n,m=w%n;
    Int need=d*(d+1)/2*n+(d+1)*m+(k-1);
    // x >= 0 -> all WA canceled

    auto floor=[&](Int x,Int y){
      if(x>=0) return x/y;
      return x/y-(abs(x)%y!=0);
    };
    cout<<floor(a-need,n)<<newl;
    return 0;
  }

  Int ans=-2;
  if(n-k+1<=w) chmax(ans,-1);
  if(k-1<=a) chmax(ans,0);

  if(ans<-1){
    cout<<":("<<newl;
    return 0;
  }

  if(ans==-1){
    cout<<ans<<newl;
    return 0;
  }

  // x >= 0
  // (x + 1) * (k - 1) + x <= a
  // x * k + k - x - 1 + x <= a
  // x * k <= a - (k - 1)
  // x <= (a - (k - 1)) / k
  cout<< (a - (k - 1)) / k << newl;
  return 0;
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int T;
  cin>>T;
  while(T--) solve();
  return 0;
}
0