結果
| 問題 |
No.951 【本日限定】1枚頼むともう1枚無料!
|
| コンテスト | |
| ユーザー |
noshi91
|
| 提出日時 | 2019-12-14 00:09:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 3,344 bytes |
| コンパイル時間 | 536 ms |
| コンパイル使用メモリ | 64,688 KB |
| 最終ジャッジ日時 | 2024-11-14 21:57:07 |
| 合計ジャッジ時間 | 1,048 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function 'void n91::main_()':
main.cpp:115:50: error: 'numeric_limits' is not a member of 'std'
115 | std::vector<i32> dp(k + 1, 0), dpf(k + 1, std::numeric_limits<i32>::lowest());
| ^~~~~~~~~~~~~~
main.cpp:115:68: error: expected primary-expression before '>' token
115 | std::vector<i32> dp(k + 1, 0), dpf(k + 1, std::numeric_limits<i32>::lowest());
| ^
main.cpp:115:71: error: '::lowest' has not been declared
115 | std::vector<i32> dp(k + 1, 0), dpf(k + 1, std::numeric_limits<i32>::lowest());
| ^~~~~~
ソースコード
//#define NDEBUG
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <utility>
#include <vector>
namespace n91 {
using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;
struct rep {
struct itr {
usize i;
constexpr itr(const usize i) noexcept : i(i) {}
void operator++() noexcept { ++i; }
constexpr usize operator*() const noexcept { return i; }
constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
};
const itr f, l;
constexpr rep(const usize f, const usize l) noexcept
: f(std::min(f, l)), l(l) {}
constexpr auto begin() const noexcept { return f; }
constexpr auto end() const noexcept { return l; }
};
struct revrep {
struct itr {
usize i;
constexpr itr(const usize i) noexcept : i(i) {}
void operator++() noexcept { --i; }
constexpr usize operator*() const noexcept { return i; }
constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
};
const itr f, l;
constexpr revrep(const usize f, const usize l) noexcept
: f(l - 1), l(std::min(f, l) - 1) {}
constexpr auto begin() const noexcept { return f; }
constexpr auto end() const noexcept { return l; }
};
template <class T> auto md_vec(const usize n, const T &value) {
return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) noexcept {
if (a < b) {
return b - a;
} else {
return a - b;
}
}
template <class T> void chmin(T &a, const T &b) noexcept {
if (b < a) {
a = b;
}
}
template <class T> void chmax(T &a, const T &b) noexcept {
if (a < b) {
a = b;
}
}
template <class F> class fix_point : private F {
public:
explicit constexpr fix_point(F &&f) : F(std::forward<F>(f)) {}
template <class... Args>
constexpr decltype(auto) operator()(Args &&... args) const {
return F::operator()(*this, std::forward<Args>(args)...);
}
};
template <class F> constexpr decltype(auto) make_fix(F &&f) {
return fix_point<F>(std::forward<F>(f));
}
template <class T> T scan() {
T ret;
std::cin >> ret;
return ret;
}
} // namespace n91
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
namespace n91 {
void main_() {
/*
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
//*/
const usize n = scan<usize>();
const usize k = scan<usize>();
struct pizza_t {
usize p;
i32 d;
};
std::vector<pizza_t> pizza(n);
for (auto &e : pizza) {
std::cin >> e.p >> e.d;
}
std::sort(pizza.begin(), pizza.end(),
[](const auto &l, const auto &r) { return l.p > r.p; });
std::vector<i32> dp(k + 1, 0), dpf(k + 1, std::numeric_limits<i32>::lowest());
for (const auto &e : pizza) {
for (const usize i : revrep(0, k + 1)) {
if (i + e.p <= k) {
chmax(dpf[i + e.p], dp[i] + e.d);
}
chmax(dp[i], dpf[i] + e.d);
}
}
std::cout << std::max(dp[k], dpf[k]) << std::endl;
}
} // namespace n91
int main() {
n91::main_();
return 0;
}
noshi91