-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f94eba
commit e8735a7
Showing
7 changed files
with
199 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
4 10 | ||
1 2 3 4 | ||
4 100 | ||
1 2 3 4 | ||
4 6 | ||
1 2 3 4 | ||
0 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
ifstream fin("copyingBooks_UVA714.in"); | ||
ofstream fout("copyingBooks_UVA714.out"); | ||
|
||
int main() | ||
{ | ||
long long testCase; fin >> testCase; | ||
for (long long t = 1; t <= testCase; ++t) | ||
{ | ||
long long m, k; fin >> m >> k; | ||
|
||
long long l = 0, r = 0; | ||
vector<long long> a(m); | ||
for (long long i = 0; i <= m - 1; ++i) | ||
{ | ||
fin >> a[i]; | ||
|
||
r += a[i]; | ||
} | ||
|
||
set<long long> s; | ||
while (l <= r) | ||
{ | ||
long long mid = (l + r) / 2, | ||
kc = k, i = m - 1, | ||
now = 0; | ||
s.clear(); | ||
|
||
while (kc >= 1) | ||
{ | ||
if (kc == 1) | ||
{ | ||
while (i >= 0) | ||
{ | ||
now += a[i]; | ||
--i; | ||
} | ||
break; | ||
} | ||
else if (i < kc - 1) | ||
{ | ||
now = 0; | ||
s.insert(i + 1); | ||
--kc; | ||
} | ||
else if (now + a[i] > mid) | ||
{ | ||
now = 0; | ||
s.insert(i + 1); | ||
--kc; | ||
} | ||
else | ||
{ | ||
now += a[i]; | ||
--i; | ||
} | ||
} | ||
|
||
if (now <= mid) | ||
{ | ||
if (r == mid) break; | ||
r = mid; | ||
} | ||
else | ||
{ | ||
l = mid + 1; | ||
} | ||
} | ||
|
||
vector<long long> fence_bool(m, 0); | ||
for (auto it = s.begin(); it != s.end(); ++it) | ||
{ | ||
long long pos = *it; | ||
fence_bool[pos] = 1; | ||
} | ||
|
||
for (long long i = 0; i <= m - 1; ++i) | ||
{ | ||
if (fence_bool[i] == 1) fout << " /"; | ||
if (i > 0) fout << ' '; | ||
fout << a[i]; | ||
} | ||
fout << '\n'; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
2 | ||
9 3 | ||
100 200 300 400 500 600 700 800 900 | ||
5 4 | ||
100 100 100 100 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
100 200 300 400 500 / 600 700 / 800 900 | ||
100 / 100 / 100 / 100 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
|
||
int main() | ||
{ | ||
ios_base::sync_with_stdio(false); | ||
std::cin.tie(NULL); | ||
long long testCase; cin >> testCase; | ||
for (long long t = 1; t <= testCase; ++t) | ||
{ | ||
long long m, k; cin >> m >> k; | ||
|
||
long long l = 0, r = 0; | ||
vector<long long> a(m); | ||
for (long long i = 0; i <= m - 1; ++i) | ||
{ | ||
cin >> a[i]; | ||
|
||
r += a[i]; | ||
} | ||
|
||
set<long long> s; | ||
while (l <= r) | ||
{ | ||
long long mid = (l + r) / 2, | ||
kc = k, i = m - 1, | ||
now = 0; | ||
s.clear(); | ||
|
||
while (kc >= 1) | ||
{ | ||
if (kc == 1) | ||
{ | ||
while (i >= 0) | ||
{ | ||
now += a[i]; | ||
--i; | ||
} | ||
break; | ||
} | ||
else if (i < kc - 1) | ||
{ | ||
now = 0; | ||
s.insert(i + 1); | ||
--kc; | ||
} | ||
else if (now + a[i] > mid) | ||
{ | ||
now = 0; | ||
s.insert(i + 1); | ||
--kc; | ||
} | ||
else | ||
{ | ||
now += a[i]; | ||
--i; | ||
} | ||
} | ||
|
||
if (now <= mid) | ||
{ | ||
if (r == mid) break; | ||
r = mid; | ||
} | ||
else | ||
{ | ||
l = mid + 1; | ||
} | ||
} | ||
|
||
vector<long long> fence_bool(m, 0); | ||
for (auto it = s.begin(); it != s.end(); ++it) | ||
{ | ||
long long pos = *it; | ||
fence_bool[pos] = 1; | ||
} | ||
|
||
for (long long i = 0; i <= m - 1; ++i) | ||
{ | ||
if (fence_bool[i] == 1) cout << " /"; | ||
if (i > 0) cout << ' '; | ||
cout << a[i]; | ||
} | ||
cout << '\n'; | ||
} | ||
|
||
cout.flush(); | ||
return 0; | ||
} | ||
|