結果
問題 | No.817 Coin donation |
ユーザー | nu50218 |
提出日時 | 2019-04-19 21:32:03 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 32 ms / 2,000 ms |
コード長 | 2,509 bytes |
コンパイル時間 | 1,517 ms |
コンパイル使用メモリ | 170,104 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-22 16:47:37 |
合計ジャッジ時間 | 2,436 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 3 ms
6,940 KB |
testcase_06 | AC | 6 ms
6,940 KB |
testcase_07 | AC | 7 ms
6,944 KB |
testcase_08 | AC | 22 ms
6,940 KB |
testcase_09 | AC | 8 ms
6,944 KB |
testcase_10 | AC | 32 ms
6,940 KB |
testcase_11 | AC | 31 ms
6,940 KB |
testcase_12 | AC | 32 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 2 ms
6,944 KB |
testcase_15 | AC | 2 ms
6,944 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast; /* define */ #define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++) #define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--) #define ALL(X) (X).begin(),(X).end() #define pb push_back #define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)) #define debug(x) cerr<<#x<<':'<<x<<endl; #define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl; #define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} #define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;} #define ctoi(C) (C-'0') #define pow2(x) ((long long)((long long)1<<x)) /* alias */ using ll = long long; using ld = long double; using vi = vector<int>; using vii = vector<vector<int>>; using vl = vector<long long>; using vll = vector<vector<long long>>; using pi = pair<int,int>; using pl = pair<long long,long long>; template<typename T> using PQ = priority_queue<T>; template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>; /* const */ const long long dx[] = {1,0,-1,0}; const long long dy[] = {0,1,0,-1}; const long long dx8[] = {1,1,0,-1,-1,-1,0,1}; const long long dy8[] = {0,1,1,1,0,-1,-1,-1}; const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0}; const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0}; const int INF = 1000000007; const long long LINF = 1000000000000000007; /* func */ template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;} template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;} long long max(long long x,int y){return max(x,(long long)y);} long long max(int x,long long y){return max((long long)x,y);} long long min(long long x,int y){return min(x,(long long)y);} long long min(int x,long long y){return min((long long)x,y);} /* liblary */ /* main */ ll N,K; vl A,B; // check(x) := x 未満の効果がK枚未満か? bool check(ll x){ ll ans = 0; FOR(i,0,N){ if(B[i] < x){ ans += B[i] - A[i] + 1; } else if(A[i] < x){ ans += x - A[i]; } } return ans < K; } signed main(){ cin >> N >> K; A.resize(N); B.resize(N); FOR(i,0,N)cin >> A[i] >> B[i]; ll imax = LINF; ll imin = 0; while(imax - imin > 1){ ll imid = (imax + imin) / 2; if(check(imid))imin = imid; else imax = imid; } cout << imin << endl; }