#include "festival.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(v) (v).begin(), (v).end()
const int LIM = 1e15;
ll safe_mul(ll x, ll y)
{
if(x * y >= LIM) return LIM;
return x * y;
}
std::vector<int> max_coupons(int aa, std::vector<int> P, std::vector<int> T) {
ll A = aa;
int n = T.size();
vector<int> one, two;
for(int i = 0; i < n; i++)
{
if(T[i] == 1) one.push_back(i);
else two.push_back(i);
}
sort(all(one), [&](int i, int j)
{
return P[i] < P[j];
});
sort(all(two), [&](int i, int j)
{
return P[i] < P[j];
});
vector<ll> pref((int)one.size());
ll sum = 0;
for(int i = 0; i < one.size(); i++)
{
sum += P[one[i]];
pref[i] = sum;
}
pref.push_back(LLONG_MAX);
auto go = [&](int tok)
{
int ans = 0;
for(int i : one)
{
ans++;
if(tok < P[i]) break;
tok -= P[i];
}
return ans;
};
int x = lower_bound(all(pref), A + 1) - pref.begin();
int y = 0;
int mx = x;
for(int i = 0; i < two.size(); i++)
{
if(A < P[two[i]]) break;
A = safe_mul(A - P[two[i]], 2);
int j = lower_bound(all(pref), A + 1) - pref.begin();
int tot = (i + 1 + j);
if(tot > mx)
{
x = j;
y = i + 1;
mx = x + y;
}
}
vector<int> ans;
for(int i = 0; i < y; i++) ans.push_back(two[i]);
for(int i = 0; i < x; i++) ans.push_back(one[i]);
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
festival.cpp:6:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+15' to '2147483647' [-Woverflow]
6 | const int LIM = 1e15;
| ^~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |