最終的に、あなたはナップザック問題の解決策を求めています。ナップザック問題にはさまざまな形があります。
簡単なアプローチは次の疑似コードによるものですが、これはすべての入力に対して最適なソリューションを生成するわけではありません(上記の記事を参照してください)。
while (there are unallocated files) {
create a new, empty directory
set remaining space to 700,000,000
while (the size of the smallest unallocated is at most (<=) the remaining space) {
copy into the current the largest unallocated file with size at most the remaining space
subtract that file's size from the remaining space
remove that file from the set of unallocated files
}
burn the current directory
}
(もちろん、これは単一のファイルのサイズが 700MB を超えないことを前提としています。可能であれば、そのようなファイルを未割り当てリストから削除してください。そうしないと、上記の方法で無限に多くの空のディレクトリが作成されます! ;-)