#include <iostream> using namespace std; const int MAX_SIZE=200000; long int Client[MAX_SIZE]; long int Bake [MAX_SIZE]; int ClientCount, BakeCount; void ReadData(){ cin >> ClientCount >> BakeCount; for(int oLoop = 0; oLoop < ClientCount; oLoop++){ cin >> Client[oLoop]; } for(int oLoop = 0; oLoop < BakeCount; oLoop++){ cin >> Bake[oLoop]; } } void Compute(long int aValue){ long int oTime = 0; long int oTimeStart; long int oTimeEnd = 0; for(int oLoop = 0; oLoop < ClientCount; oLoop++){ oTimeStart = Client[oLoop]-aValue; if(oTimeStart<oTimeEnd){ oTimeEnd+=aValue; }else{ oTimeEnd=Client[oLoop]; } if(oTimeEnd>Client[oLoop]){ oTime += oTimeEnd - Client[oLoop]; } } cout << oTime << endl; } void Analize(){ for(int oLoop=0;oLoop<BakeCount;oLoop++){ Compute(Bake[oLoop]); } } int main(){ ReadData(); Analize(); return 0; } /*/ 4 3 3 10 11 23 4 2 5 /*/
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 | #include <iostream> using namespace std; const int MAX_SIZE=200000; long int Client[MAX_SIZE]; long int Bake [MAX_SIZE]; int ClientCount, BakeCount; void ReadData(){ cin >> ClientCount >> BakeCount; for(int oLoop = 0; oLoop < ClientCount; oLoop++){ cin >> Client[oLoop]; } for(int oLoop = 0; oLoop < BakeCount; oLoop++){ cin >> Bake[oLoop]; } } void Compute(long int aValue){ long int oTime = 0; long int oTimeStart; long int oTimeEnd = 0; for(int oLoop = 0; oLoop < ClientCount; oLoop++){ oTimeStart = Client[oLoop]-aValue; if(oTimeStart<oTimeEnd){ oTimeEnd+=aValue; }else{ oTimeEnd=Client[oLoop]; } if(oTimeEnd>Client[oLoop]){ oTime += oTimeEnd - Client[oLoop]; } } cout << oTime << endl; } void Analize(){ for(int oLoop=0;oLoop<BakeCount;oLoop++){ Compute(Bake[oLoop]); } } int main(){ ReadData(); Analize(); return 0; } /*/ 4 3 3 10 11 23 4 2 5 /*/ |