#include <map>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <sstream>
int main()
{
auto counts = std::string{};
std::getline(std::cin, counts);
std::istringstream first_line{counts};
long int clients_count, ovens_count;
first_line >> clients_count;
first_line >> ovens_count;
auto clients_line = std::string{};
auto clients = std::vector<long int>{};
std::getline(std::cin, clients_line);
std::istringstream clients_str{clients_line};
clients.reserve(clients_count);
for(int i = 0; i < clients_count; ++i)
clients_str >> clients[i];
auto ovens_line = std::string{};
auto ovens = std::vector<long int>{};
std::getline(std::cin, ovens_line);
std::istringstream ovens_str{ovens_line};
ovens.reserve(ovens_count);
for(int i = 0; i < ovens_count; ++i)
ovens_str >> ovens[i];
for(int i = 0; i < ovens_count; ++i)
{
auto oven = ovens[i];
long unsigned int wait = 0;
long unsigned int upper_bound = 0;
for(int i = 0; i < clients_count; ++i)
{
auto client = clients[i];
if(client - oven < 0)
{
upper_bound += oven;
}
else if(upper_bound > client - oven)
{
upper_bound = upper_bound + oven;
}
else
{
upper_bound = client;
}
wait += upper_bound - client;
}
std::cout << wait << std::endl;
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | #include <map> #include <iostream> #include <string> #include <vector> #include <map> #include <sstream> int main() { auto counts = std::string{}; std::getline(std::cin, counts); std::istringstream first_line{counts}; long int clients_count, ovens_count; first_line >> clients_count; first_line >> ovens_count; auto clients_line = std::string{}; auto clients = std::vector<long int>{}; std::getline(std::cin, clients_line); std::istringstream clients_str{clients_line}; clients.reserve(clients_count); for(int i = 0; i < clients_count; ++i) clients_str >> clients[i]; auto ovens_line = std::string{}; auto ovens = std::vector<long int>{}; std::getline(std::cin, ovens_line); std::istringstream ovens_str{ovens_line}; ovens.reserve(ovens_count); for(int i = 0; i < ovens_count; ++i) ovens_str >> ovens[i]; for(int i = 0; i < ovens_count; ++i) { auto oven = ovens[i]; long unsigned int wait = 0; long unsigned int upper_bound = 0; for(int i = 0; i < clients_count; ++i) { auto client = clients[i]; if(client - oven < 0) { upper_bound += oven; } else if(upper_bound > client - oven) { upper_bound = upper_bound + oven; } else { upper_bound = client; } wait += upper_bound - client; } std::cout << wait << std::endl; } } |
English