#include <fstream>
#include <iostream>
#include <vector>
std::vector<long> customer;
std::vector<long> oven;
void read(std::istream & str)
{
int n, m, i;
str >> n >> m;
if( n < 0 || m < 0 )
{
std::cout << "ops" << std::endl;
return;
}
customer.resize(n);
oven.resize(m);
for(i = 0 ; i < n ; ++i)
{
str >> customer[i];
}
for(i = 0 ; i < m ; ++i)
{
str >> oven[i];
}
}
void calc(long o)
{
long t, m;
if( customer.empty() )
return;
t = customer[0];
m = 0;
t = t - o;
if( t < 0 )
t = 0;
t = t + o;
m = t - customer[0];
for(size_t c = 1 ; c < customer.size() ; ++c)
{
if( customer[c] - o >= t )
t = customer[c] - o;
long dt = t + o - customer[c];
m += dt;
t += o;
}
std::cout << m << "\n";
}
void calc()
{
for(size_t m = 0 ; m < oven.size() ; ++m)
{
calc(oven[m]);
}
}
int main()
{
// std::ifstream f("input.txt");
//
// if( !f )
// {
// std::cout << "input file problem" << std::endl;
// return 1;
// }
//
// read(f);
// calc();
read(std::cin);
calc();
}
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | #include <fstream> #include <iostream> #include <vector> std::vector<long> customer; std::vector<long> oven; void read(std::istream & str) { int n, m, i; str >> n >> m; if( n < 0 || m < 0 ) { std::cout << "ops" << std::endl; return; } customer.resize(n); oven.resize(m); for(i = 0 ; i < n ; ++i) { str >> customer[i]; } for(i = 0 ; i < m ; ++i) { str >> oven[i]; } } void calc(long o) { long t, m; if( customer.empty() ) return; t = customer[0]; m = 0; t = t - o; if( t < 0 ) t = 0; t = t + o; m = t - customer[0]; for(size_t c = 1 ; c < customer.size() ; ++c) { if( customer[c] - o >= t ) t = customer[c] - o; long dt = t + o - customer[c]; m += dt; t += o; } std::cout << m << "\n"; } void calc() { for(size_t m = 0 ; m < oven.size() ; ++m) { calc(oven[m]); } } int main() { // std::ifstream f("input.txt"); // // if( !f ) // { // std::cout << "input file problem" << std::endl; // return 1; // } // // read(f); // calc(); read(std::cin); calc(); } |
English