Submission #61818027


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
const int inf = 1e9;
void solve() {
int n, m; cin >> n >> m;
vector<int> p(n);
for(int i = 0; i < n; ++i) cin >> p[i];
auto ok = [&] (int x) {
int res = 0;
for(int i = 0; i < n; ++i) {
int mx = (x / p[i] + 1) / 2;
if(mx > inf) return false;
mx *= mx;
if(mx > m / p[i]) return false;
if(res > m - mx * p[i]) return false;
res += mx * p[i];
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long

const int inf = 1e9;

void solve() {
    int n, m; cin >> n >> m;
    vector<int> p(n);
    for(int i = 0; i < n; ++i) cin >> p[i];

    auto ok = [&] (int x) {
        int res = 0;
        for(int i = 0; i < n; ++i) {
            int mx = (x / p[i] + 1) / 2;
            if(mx > inf) return false;
            mx *= mx;
            if(mx > m / p[i]) return false;
            if(res > m - mx * p[i]) return false;
            res += mx * p[i];
        }

        return res <= m;
    };

    int l = 0, r = m + 2;
    while(r - l > 1) {
        int mid = (r + l) >> 1;
        if(ok(mid)) l = mid;
        else r = mid;
    }

    int ans = 0;
    int nxt = 1e18;
    for(int i = 0; i < n; ++i) {
        int qt = (l / p[i] + 1) / 2;
        ans += qt;
        m -= qt * qt * p[i];
        nxt = min(nxt, (2*(qt + 1) - 1) * p[i]);
    }

    cout << ans + m / nxt;
}

int32_t main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    solve();
}

Submission Info

Submission Time
Task E - Square Price
User picramide
Language C++ 20 (gcc 12.2)
Score 475
Code Size 1093 Byte
Status AC
Exec Time 57 ms
Memory 4768 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 2
AC × 26
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3440 KB
00_sample_01.txt AC 1 ms 3628 KB
01_random_00.txt AC 53 ms 4592 KB
01_random_01.txt AC 55 ms 4700 KB
01_random_02.txt AC 54 ms 4708 KB
01_random_03.txt AC 54 ms 4592 KB
01_random_04.txt AC 54 ms 4584 KB
01_random_05.txt AC 51 ms 4608 KB
01_random_06.txt AC 53 ms 4640 KB
01_random_07.txt AC 53 ms 4768 KB
01_random_08.txt AC 55 ms 4760 KB
01_random_09.txt AC 54 ms 4688 KB
01_random_10.txt AC 6 ms 3504 KB
01_random_11.txt AC 47 ms 4340 KB
01_random_12.txt AC 5 ms 3476 KB
01_random_13.txt AC 11 ms 3508 KB
01_random_14.txt AC 33 ms 4064 KB
01_random_15.txt AC 52 ms 4580 KB
01_random_16.txt AC 26 ms 3872 KB
01_random_17.txt AC 17 ms 3652 KB
01_random_18.txt AC 40 ms 4324 KB
01_random_19.txt AC 46 ms 4276 KB
01_random_20.txt AC 33 ms 4700 KB
01_random_21.txt AC 57 ms 4628 KB
01_random_22.txt AC 1 ms 3508 KB
01_random_23.txt AC 1 ms 3568 KB


2025-03-05 (Wed)
20:48:01 +00:00