← 返回 coinbase 的题目列表Cloud Storage Management
类型:online_judge
Implement a cloud storage management system supporting user management, file operations, and storage capacity management. Requirements are as follows:
Implement add_user(user_id, capacity) method to create a user with specified storage capacity.
Implement update_capacity(user_id, new_capacity) method to update user's storage capacity. If the user exceeds the new capacity, delete files from largest to smallest until the limit is satisfied.
Implement compress_file(user_id, file_name) and decompress_file(user_id, file_name) methods to convert between file name and its compressed version (e.g., file.txt <-> file.txt.compressed), and adjust file size (compressed size is half, decompressed size is double).
Ensure that users and files exist as needed and perform operations accordingly.
Assume each file has a fixed initial size, and file operations should consider performance and robustness.
Sample Input:
add_user('user1', 1000)
add_user('user2', 500)
compress_file('user1', 'photo.png')
update_capacity('user1', 400)
decompress_file('user1', 'photo.png.compressed')
Hints:
Consider prioritizing space reduction and access efficiency in file deletions and storage operations.
Data scale:
Up to 1000 users
Each user can have up to 2000 files
Single file max size 100 MB
Example
Input
add_user('user1', 1000)
add_user('user2', 500)
update_capacity('user1', 400)