Submission #1270416

#TimeUsernameProblemLanguageResultExecution timeMemory
1270416steveonalexCity (BOI06_city)C++20
100 / 100
68 ms580 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(a, b);}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
 
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ull mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
 
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
double rngesus_d(double l, double r){
    double wow = (double) ((ull) rng()) / ((ull)(0-1));
    return wow * (r - l) + l;
}
 
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }
 
template <class T>
    void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
        for(auto item: container) out << item << separator;
        out << finish;
    }
 
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

ll get_border(ll x){
    return (x+1) * (x+1) - (x-1) * (x-1);
}

ll n, t, k; 
vector<ll> a, b;

pair<ll, ll> calc(ll lambda){
    int j = k;
    pair<ll, ll> ans = make_pair(0, 0);
    for(int i = 1; i < 2e6; ++i){
        while(j > 0 && (t * (i-1) + a[j]) > lambda) j--;
        if (j == 0) break;

        ll amount = get_border(i);

        ans.second += amount * j;
        ans.first += amount * (b[j] + t * (i-1) * j);
    }

    return ans;
}

void solve(){
    cin >> n >> t >> k;
    a.resize(k+1);
    for(int i = 1; i <= k; ++i) cin >> a[i];

    b = a;
    for(int i = 1; i<=k; ++i) b[i] += b[i-1];

    ll l = 0, r = 2e12;
    while(l < r){
        ll mid = (l + r) >> 1;
        pair<ll, ll> tmp = calc(mid);
        if (tmp.second >= n) r = mid;
        else l = mid + 1;
    }

    pair<ll, ll> tmp = calc(l);
    tmp.first -= l * (tmp.second - n);
    cout << tmp.first << "\n";
}

int main(void){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    clock_t cock = clock();

    solve();

    cerr << "Time elapsed: " << clock() - cock << "ms!\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...