//============================================================================
// Name : zap.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
long long tn[200010];
int dm[200010];
long long tmax, tmaxPom, tmaxStart, tmaxStop;
int n = 0, m = 0;
long long obliczTmax(int tempdm);
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> tn[i];
}
for (int i = 0; i < m; i++) {
cin >> dm[i];
}
for (int i = 0; i < m; i++) {
cout << obliczTmax(dm[i]) << endl;
}
return 0;
}
long long obliczTmax(int tempdm) {
tmax = 0;
if (n == 1) {
if (tempdm - tn[0] < 0)
return 0;
else
return tempdm - tn[0];
}
tmaxStart = tmaxStop = 0;
long long pomtn, pomtnwczes;
for (int i = 0; i < n; i++) {
pomtn = tn[i];
if (pomtn < tmaxStop + tempdm) {
tmaxStop += tempdm;
tmaxStart = pomtn;
tmaxPom = tmaxStop - tmaxStart;
tmax += tmaxPom;
// cout << "tmaxpom"<< tmaxPom<<endl;
// cout <<"if" << tmaxStop<<endl;
} else {
tmaxStart = pomtn;
if (i + 1 < n) {
if ((tmaxStop + tempdm) <= tn[i + 1])
tmaxStop = pomtn;
}
// cout <<"else" << tmaxStop<<endl;
}
}
return tmax;
}
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 | //============================================================================ // Name : zap.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> using namespace std; long long tn[200010]; int dm[200010]; long long tmax, tmaxPom, tmaxStart, tmaxStop; int n = 0, m = 0; long long obliczTmax(int tempdm); int main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> tn[i]; } for (int i = 0; i < m; i++) { cin >> dm[i]; } for (int i = 0; i < m; i++) { cout << obliczTmax(dm[i]) << endl; } return 0; } long long obliczTmax(int tempdm) { tmax = 0; if (n == 1) { if (tempdm - tn[0] < 0) return 0; else return tempdm - tn[0]; } tmaxStart = tmaxStop = 0; long long pomtn, pomtnwczes; for (int i = 0; i < n; i++) { pomtn = tn[i]; if (pomtn < tmaxStop + tempdm) { tmaxStop += tempdm; tmaxStart = pomtn; tmaxPom = tmaxStop - tmaxStart; tmax += tmaxPom; // cout << "tmaxpom"<< tmaxPom<<endl; // cout <<"if" << tmaxStop<<endl; } else { tmaxStart = pomtn; if (i + 1 < n) { if ((tmaxStop + tempdm) <= tn[i + 1]) tmaxStop = pomtn; } // cout <<"else" << tmaxStop<<endl; } } return tmax; } |
English