Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Nguyen Huu Hoang Minh
- #include <bits/stdc++.h>
- #define sz(x) int(x.size())
- #define all(x) x.begin(),x.end()
- #define reset(x) memset(x, 0,sizeof(x))
- #define pb push_back
- #define mp make_pair
- #define fi first
- #define se second
- #define N 100005
- #define remain(x) if (x > MOD) x -= MOD
- #define ii pair<int, int>
- #define iiii pair< ii , ii >
- #define viiii vector< iiii >
- #define vi vector<int>
- #define vii vector< ii >
- #define bit(x, i) (((x) >> (i)) & 1)
- #define Task "test"
- #define int long long
- using namespace std;
- typedef long double ld;
- const int inf = 1e10;
- const int minf = -1e10;
- int n, m;
- int a[N], b[N];
- void readfile()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);cout.tie(0);
- if (fopen(Task".inp","r"))
- {
- freopen(Task".inp","r",stdin);
- //freopen(Task".out","w",stdout);
- }
- cin >> n >> m;
- for(int i=1; i<=n; i++){
- cin >> a[i] >> b[i];
- }
- }
- bool ok(int day){
- int product = 0;
- for(int i=1; i<=n; i++){
- int bi = b[i]+1;
- int full = day/bi;
- int lef = day%bi;
- product += full*b[i]*a[i] + lef*a[i];
- }
- return product >= m;
- }
- void proc()
- {
- int l = 1, r = 1e18;
- while (r-l>0){
- int mid = (l+r)/2;
- if (ok(mid)) r = mid;
- else l = mid+1;
- }
- cout << l;
- }
- signed main()
- {
- readfile();
- proc();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement