Submission #44955256
Source Code Expand
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
template <class T>
std::ostream &operator<<(std::ostream &out, const std::vector<std::vector<T>> &r){
if(r.size() == 0){
out << "||";
return out;
}
for(const auto&v : r) out << v << endl;
out << endl;
return out;
}
template <class T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &r){
if(r.size() == 0){
out << "[]";
return out;
}
out << "[";
for(int i{}; i < (int)r.size() - 1; ++i) out << r[i] << ",";
out << r.back() << "]";
return out;
}
template <class T>
std::ostream &operator<<(std::ostream &out, const std::set<T> &r){
if(r.size() == 0){
out << "{}";
return out;
}
out << "{";
auto e = r.end(); --e;
for(auto it = r.begin(); it != e; ++it) out << *it << ",";
out << *e << "}";
return out;
}
template <class T, class U>
std::ostream &operator<<(std::ostream &out, const std::map<T, U> &r){
if(r.size() == 0){
out << "{}";
return out;
}
out << "{";
auto e = r.end(); --e;
for(auto it = r.begin(); it != e; ++it) out << it -> first << ":" << it -> second << ",";
out << e -> first << ":" << e -> second << "}";
return out;
}
template <class T, class U>
std::ostream &operator<<(std::ostream &out, const std::pair<T, U> &r){
out << "(" << r.first << "," << r.second << ")";
return out;
}
void solve(){
int n;
cin >> n;
vector<int> x(n), y(n), z(n);
int Z = 0, T = 0;
for (int i = 0; i < n; i++)
{
cin >> x[i] >> y[i] >> z[i];
Z += z[i];
if(x[i] > y[i]) T += z[i];
}
constexpr ll inf = 1e16;
vector<ll> d(Z+1, inf);
d[T] = 0;
for (int i = 0; i < n; i++)
{
if(x[i] > y[i]) continue;
int k = (y[i] - x[i] + 1) / 2;
for (int j = Z; j >= z[i]; j--)
{
chmin(d[j], d[j-z[i]] + k);
}
}
ll ans = inf;
for (int i = (Z+1)/2; i <= Z; i++)
{
chmin(ans, d[i]);
}
cout << ans << endl;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
solve();
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - President |
| User | Motsu_xe |
| Language | C++ 20 (gcc 12.2) |
| Score | 400 |
| Code Size | 2509 Byte |
| Status | AC |
| Exec Time | 10 ms |
| Memory | 3964 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.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, 02_max_00.txt, 03_hack_00.txt, 03_hack_01.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3508 KiB |
| 00_sample_01.txt | AC | 1 ms | 3448 KiB |
| 00_sample_02.txt | AC | 1 ms | 3444 KiB |
| 00_sample_03.txt | AC | 1 ms | 3452 KiB |
| 01_random_00.txt | AC | 3 ms | 3544 KiB |
| 01_random_01.txt | AC | 1 ms | 3464 KiB |
| 01_random_02.txt | AC | 6 ms | 3904 KiB |
| 01_random_03.txt | AC | 8 ms | 3836 KiB |
| 01_random_04.txt | AC | 4 ms | 3824 KiB |
| 01_random_05.txt | AC | 4 ms | 3432 KiB |
| 01_random_06.txt | AC | 3 ms | 3820 KiB |
| 01_random_07.txt | AC | 10 ms | 3736 KiB |
| 01_random_08.txt | AC | 1 ms | 3508 KiB |
| 01_random_09.txt | AC | 2 ms | 3460 KiB |
| 01_random_10.txt | AC | 5 ms | 3768 KiB |
| 01_random_11.txt | AC | 9 ms | 3816 KiB |
| 01_random_12.txt | AC | 3 ms | 3812 KiB |
| 01_random_13.txt | AC | 1 ms | 3532 KiB |
| 01_random_14.txt | AC | 1 ms | 3548 KiB |
| 01_random_15.txt | AC | 2 ms | 3808 KiB |
| 01_random_16.txt | AC | 2 ms | 3644 KiB |
| 01_random_17.txt | AC | 9 ms | 3964 KiB |
| 01_random_18.txt | AC | 2 ms | 3516 KiB |
| 01_random_19.txt | AC | 8 ms | 3828 KiB |
| 01_random_20.txt | AC | 2 ms | 3592 KiB |
| 01_random_21.txt | AC | 10 ms | 3808 KiB |
| 01_random_22.txt | AC | 6 ms | 3844 KiB |
| 01_random_23.txt | AC | 1 ms | 3496 KiB |
| 02_max_00.txt | AC | 7 ms | 3828 KiB |
| 03_hack_00.txt | AC | 7 ms | 3736 KiB |
| 03_hack_01.txt | AC | 7 ms | 3844 KiB |