結果

問題 No.817 Coin donation
ユーザー wunderkammer2wunderkammer2
提出日時 2021-04-20 23:02:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 3,745 bytes
コンパイル時間 1,469 ms
コンパイル使用メモリ 140,360 KB
実行使用メモリ 15,612 KB
最終ジャッジ日時 2023-09-17 08:57:37
合計ジャッジ時間 4,058 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 16 ms
4,708 KB
testcase_07 AC 22 ms
5,216 KB
testcase_08 AC 118 ms
11,680 KB
testcase_09 AC 27 ms
5,520 KB
testcase_10 AC 189 ms
15,544 KB
testcase_11 AC 192 ms
15,604 KB
testcase_12 AC 185 ms
15,612 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>     //sort,二分探索,など
#include<bit>           //popcount
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム(標準入力変更用)
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//#include<atcoder\all>
//using namespace atcoder;

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
const int MAXR = 100000;             //10^5:配列の最大のrange

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in1(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define in4(x1, x2, x3, x4) cin >> x1 >> x2 >> x3 >> x4
#define in5(x1, x2, x3, x4, x5) cin >> x1 >> x2 >> x3 >> x4 >> x5
#define in6(x1, x2, x3, x4, x5, x6) cin >> x1 >> x2 >> x3 >> x4 >> x5 >> x6
#define inN(x, N) rep(i, N) in1(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
inline ll div_ceil(ll a, ll b) { return (a + (b - 1)) / b; }

map<int, int> compress(vi& X)
{
    map<int, int> m;

    sort(all(X));

    X.erase(unique(all(X)), X.end());

    rep(i, X.size()) m[X[i]] = i;

    return m;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    int N;
    ll K;
    in2(N, K);

    vi A(N), B(N);
    rep(i, N) in2(A[i], B[i]);

    vi x;
    x.push_back(0);
    rep(i, N) x.push_back(A[i]);
    rep(i, N) x.push_back(B[i] + 1);

    //座標圧縮
    auto m = compress(x);

    //いもす法
    vll c(x.size() + 2);
    rep(i, N)
    {
        c[m[A[i]]]++;
        c[m[B[i] + 1]]--;
    }

    rep(i, c.size() - 1) c[i + 1] += c[i];

    ll total = 0;

    rep(i, x.size() - 1)
    {
        ll diff = K - total;
        int from = x[i];
        int to = x[i + 1];
        ll count = c[m[from]];

        total += (to - from) * count;

        if (total < K) continue;

        outl(from + div_ceil(diff, count) - 1);

        return 0;
    }

    return 0;
}
0