結果

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

ソースコード

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;
    { // x >= 0 -> all WA canceled
      Int d=w/n,m=w%n;
      Int need=d*(d+1)/2*n+(d+1)*m+(k-1);
      if(need<=a){
        cout<<(a-need)/n<<newl;
        return 0;
      }
    }
    abort();
    Int ans=min<Int>(-1,a-w*(w+1)/2);
    cout<<ans<<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