From b07ef359caf752523a6e0fbf970588d767eaa6e9 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Fri, 2 Sep 2022 08:55:23 +0800 Subject: [PATCH] P3112 [USACO14DEC]Guard Mark G https://www.luogu.com.cn/record/85668298 --- Luogu/P3112/P3112.cpp | 72 +++++++++++++++++++++++++++++++++++++++++ Luogu/P3112/data/1.in | 3 ++ Luogu/P3112/data/1.out | 3 ++ Luogu/P3112/data/10.in | 3 ++ Luogu/P3112/data/10.out | 3 ++ Luogu/P3112/data/11.in | 3 ++ Luogu/P3112/data/11.out | 3 ++ Luogu/P3112/data/12.in | 3 ++ Luogu/P3112/data/12.out | 3 ++ Luogu/P3112/data/13.in | 3 ++ Luogu/P3112/data/13.out | 3 ++ Luogu/P3112/data/14.in | 3 ++ Luogu/P3112/data/14.out | 3 ++ Luogu/P3112/data/2.in | 3 ++ Luogu/P3112/data/2.out | 3 ++ Luogu/P3112/data/3.in | 3 ++ Luogu/P3112/data/3.out | 3 ++ Luogu/P3112/data/4.in | 3 ++ Luogu/P3112/data/4.out | 3 ++ Luogu/P3112/data/5.in | 3 ++ Luogu/P3112/data/5.out | 3 ++ Luogu/P3112/data/6.in | 3 ++ Luogu/P3112/data/6.out | 3 ++ Luogu/P3112/data/7.in | 3 ++ Luogu/P3112/data/7.out | 3 ++ Luogu/P3112/data/8.in | 3 ++ Luogu/P3112/data/8.out | 3 ++ Luogu/P3112/data/9.in | 3 ++ Luogu/P3112/data/9.out | 3 ++ 29 files changed, 156 insertions(+) create mode 100644 Luogu/P3112/P3112.cpp create mode 100644 Luogu/P3112/data/1.in create mode 100644 Luogu/P3112/data/1.out create mode 100644 Luogu/P3112/data/10.in create mode 100644 Luogu/P3112/data/10.out create mode 100644 Luogu/P3112/data/11.in create mode 100644 Luogu/P3112/data/11.out create mode 100644 Luogu/P3112/data/12.in create mode 100644 Luogu/P3112/data/12.out create mode 100644 Luogu/P3112/data/13.in create mode 100644 Luogu/P3112/data/13.out create mode 100644 Luogu/P3112/data/14.in create mode 100644 Luogu/P3112/data/14.out create mode 100644 Luogu/P3112/data/2.in create mode 100644 Luogu/P3112/data/2.out create mode 100644 Luogu/P3112/data/3.in create mode 100644 Luogu/P3112/data/3.out create mode 100644 Luogu/P3112/data/4.in create mode 100644 Luogu/P3112/data/4.out create mode 100644 Luogu/P3112/data/5.in create mode 100644 Luogu/P3112/data/5.out create mode 100644 Luogu/P3112/data/6.in create mode 100644 Luogu/P3112/data/6.out create mode 100644 Luogu/P3112/data/7.in create mode 100644 Luogu/P3112/data/7.out create mode 100644 Luogu/P3112/data/8.in create mode 100644 Luogu/P3112/data/8.out create mode 100644 Luogu/P3112/data/9.in create mode 100644 Luogu/P3112/data/9.out diff --git a/Luogu/P3112/P3112.cpp b/Luogu/P3112/P3112.cpp new file mode 100644 index 00000000..644d2ee4 --- /dev/null +++ b/Luogu/P3112/P3112.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 25; + +int n, h, ans = -1; +std::tuple a[N]; +bool vis[N]; + +void dfs(int x) { + if (x == n + 1) { + int hh = 0, ss = std::numeric_limits::max(); + + for (int i = 1; i <= n; i++) { + if (!vis[i]) continue; + + hh += std::get<0>(a[i]); + + int sum = 0; + + for (int j = i + 1; j <= n; j++) { + if (!vis[j]) continue; + + sum += std::get<1>(a[j]); + } + + ss = std::min(ss, std::get<2>(a[i]) - sum); + } + + if (hh >= h) { + ans = std::max(ans, ss); + } + + return; + } + + dfs(x + 1); + vis[x] = true; + dfs(x + 1); + vis[x] = false; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> h; + + for (int i = 1; i <= n; i++) { + cin >> std::get<0>(a[i]) >> std::get<1>(a[i]) >> std::get<2>(a[i]); + } + + std::sort(a + 1, a + 1 + n, [&](decltype(a[0]) x, decltype(a[0]) y) -> bool { + return std::get<1>(x) + std::get<2>(x) > std::get<1>(y) + std::get<2>(y); + }); + + dfs(0); + + if (ans == -1) { + cout << "Mark is too tall" << endl; + } else { + cout << ans << endl; + } + + return 0; +} diff --git a/Luogu/P3112/data/1.in b/Luogu/P3112/data/1.in new file mode 100644 index 00000000..56b2dcac --- /dev/null +++ b/Luogu/P3112/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:05112a98a18d685d75738c5ed18f64bf22435949fc625c75f55f15f606f137a8 +size 30 diff --git a/Luogu/P3112/data/1.out b/Luogu/P3112/data/1.out new file mode 100644 index 00000000..38118f32 --- /dev/null +++ b/Luogu/P3112/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3 +size 2 diff --git a/Luogu/P3112/data/10.in b/Luogu/P3112/data/10.in new file mode 100644 index 00000000..99321e81 --- /dev/null +++ b/Luogu/P3112/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:940d6beb0d00fc315172e2b20b62fcb2b3ed9fca0250ebedb3dd13e1de618127 +size 545 diff --git a/Luogu/P3112/data/10.out b/Luogu/P3112/data/10.out new file mode 100644 index 00000000..295ea24f --- /dev/null +++ b/Luogu/P3112/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fd86b0802d763c721993a962751d151a1488b07171e44bba705480e433b44e9a +size 9 diff --git a/Luogu/P3112/data/11.in b/Luogu/P3112/data/11.in new file mode 100644 index 00000000..43650867 --- /dev/null +++ b/Luogu/P3112/data/11.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:65ceea2751d4840ded07c8d92df1e42b721d59947ae4ebf2b97ab0a96c3c02e7 +size 564 diff --git a/Luogu/P3112/data/11.out b/Luogu/P3112/data/11.out new file mode 100644 index 00000000..b889b4ca --- /dev/null +++ b/Luogu/P3112/data/11.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6ff44f9b05705ddca6a2db44007119e3094b501e9ece455ee0d7b04b2c3ab357 +size 9 diff --git a/Luogu/P3112/data/12.in b/Luogu/P3112/data/12.in new file mode 100644 index 00000000..ef7acb95 --- /dev/null +++ b/Luogu/P3112/data/12.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:93eb0342dd385985bf1902e6bb58e37fe6a457d7d3e992004e27b6c8d8626e80 +size 564 diff --git a/Luogu/P3112/data/12.out b/Luogu/P3112/data/12.out new file mode 100644 index 00000000..e88b3e12 --- /dev/null +++ b/Luogu/P3112/data/12.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ccd36d3bf503b60ff6be36338af4493253c7cd9464ce6d6d38551d69832672bf +size 9 diff --git a/Luogu/P3112/data/13.in b/Luogu/P3112/data/13.in new file mode 100644 index 00000000..dd4688d0 --- /dev/null +++ b/Luogu/P3112/data/13.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7fef4b7db191202ef04b24578fc78c2f1a18d9295865cd1cfc798775409361c0 +size 564 diff --git a/Luogu/P3112/data/13.out b/Luogu/P3112/data/13.out new file mode 100644 index 00000000..6f073396 --- /dev/null +++ b/Luogu/P3112/data/13.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dbd0ba6ad3c377232e17053de8233ca443fc6b69757367dd98f533f4bd7b2b03 +size 10 diff --git a/Luogu/P3112/data/14.in b/Luogu/P3112/data/14.in new file mode 100644 index 00000000..6a2e4235 --- /dev/null +++ b/Luogu/P3112/data/14.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e96743ebeec00f778fb54d51f6d13f8987a35347d0e6e88b846715e1c09ff851 +size 535 diff --git a/Luogu/P3112/data/14.out b/Luogu/P3112/data/14.out new file mode 100644 index 00000000..8db53a9d --- /dev/null +++ b/Luogu/P3112/data/14.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:546d120b95bea6791aebd348d4c36381b254f1613536302683f9720c67f09b74 +size 10 diff --git a/Luogu/P3112/data/2.in b/Luogu/P3112/data/2.in new file mode 100644 index 00000000..f9f72abb --- /dev/null +++ b/Luogu/P3112/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5743c6a83ae8917f88438b784ce9eb056dbf085887168be7d44893cba74c6e81 +size 29 diff --git a/Luogu/P3112/data/2.out b/Luogu/P3112/data/2.out new file mode 100644 index 00000000..432b57d6 --- /dev/null +++ b/Luogu/P3112/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:129f42301007d07ef5fd3cfde4329055aaa6a544f4f249cbe1d431ae3222bdfc +size 17 diff --git a/Luogu/P3112/data/3.in b/Luogu/P3112/data/3.in new file mode 100644 index 00000000..f1eff184 --- /dev/null +++ b/Luogu/P3112/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b418c199bd817d22e7cfc132a0cc0ecdfc4f8cebe21ab2dbd6c85d57e9d12d81 +size 24 diff --git a/Luogu/P3112/data/3.out b/Luogu/P3112/data/3.out new file mode 100644 index 00000000..d76a596d --- /dev/null +++ b/Luogu/P3112/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f0b5c2c2211c8d67ed15e75e656c7862d086e9245420892a7de62cd9ec582a06 +size 2 diff --git a/Luogu/P3112/data/4.in b/Luogu/P3112/data/4.in new file mode 100644 index 00000000..1c2bcd00 --- /dev/null +++ b/Luogu/P3112/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:533b45854ee9d6caeb47f618e3d9cf22f4863a40fbf33f86e275daf7e9f9fcb0 +size 568 diff --git a/Luogu/P3112/data/4.out b/Luogu/P3112/data/4.out new file mode 100644 index 00000000..da4f42c4 --- /dev/null +++ b/Luogu/P3112/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5e3e1af6670044539fa280ecba12759a78c77f2d57d8f76e00b715cb202c54b5 +size 9 diff --git a/Luogu/P3112/data/5.in b/Luogu/P3112/data/5.in new file mode 100644 index 00000000..c9a9649e --- /dev/null +++ b/Luogu/P3112/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5bbca13fd8a2729ec0fc288ef558117f01e8c327f79f04a4bbcebb7958c07fcf +size 552 diff --git a/Luogu/P3112/data/5.out b/Luogu/P3112/data/5.out new file mode 100644 index 00000000..432b57d6 --- /dev/null +++ b/Luogu/P3112/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:129f42301007d07ef5fd3cfde4329055aaa6a544f4f249cbe1d431ae3222bdfc +size 17 diff --git a/Luogu/P3112/data/6.in b/Luogu/P3112/data/6.in new file mode 100644 index 00000000..7ae66ed9 --- /dev/null +++ b/Luogu/P3112/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:22d04d2d3bf5b29533edb7cff4bb2aef1cfa990a6f4b60b47a6ed907f4884fae +size 569 diff --git a/Luogu/P3112/data/6.out b/Luogu/P3112/data/6.out new file mode 100644 index 00000000..31a7167a --- /dev/null +++ b/Luogu/P3112/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e99083b1830e7e2e3faa8fdf153548b593426e4f7312bfc5038eb4c75ebf768f +size 9 diff --git a/Luogu/P3112/data/7.in b/Luogu/P3112/data/7.in new file mode 100644 index 00000000..866c4885 --- /dev/null +++ b/Luogu/P3112/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1e79dbf1159479f8bb735065e746607d76ff6fc3bd4aa1ccd95d1f13a89b8109 +size 84 diff --git a/Luogu/P3112/data/7.out b/Luogu/P3112/data/7.out new file mode 100644 index 00000000..d790bd49 --- /dev/null +++ b/Luogu/P3112/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2e6d31a5983a91251bfae5aefa1c0a19d8ba3cf601d0e8a706b4cfa9661a6b8a +size 2 diff --git a/Luogu/P3112/data/8.in b/Luogu/P3112/data/8.in new file mode 100644 index 00000000..80a567eb --- /dev/null +++ b/Luogu/P3112/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:efb1b9478ddc66453123268e43c797fdb754f1e944c8d9a18d326da13ad3c19e +size 547 diff --git a/Luogu/P3112/data/8.out b/Luogu/P3112/data/8.out new file mode 100644 index 00000000..e3431f66 --- /dev/null +++ b/Luogu/P3112/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0668830cba9416532e985414b517564b081901fbfa7405659cb84f4c5b8b0175 +size 10 diff --git a/Luogu/P3112/data/9.in b/Luogu/P3112/data/9.in new file mode 100644 index 00000000..201bfd3b --- /dev/null +++ b/Luogu/P3112/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:29bb62c8aebc4cfd9cf9244c0d04c675bd7f52d585017b791eb426d5ee988ba6 +size 563 diff --git a/Luogu/P3112/data/9.out b/Luogu/P3112/data/9.out new file mode 100644 index 00000000..432b57d6 --- /dev/null +++ b/Luogu/P3112/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:129f42301007d07ef5fd3cfde4329055aaa6a544f4f249cbe1d431ae3222bdfc +size 17