#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <cstdlib> #include <vector> #include <algorithm> #include <cstring> #include <string> #include <map> #include <deque> using namespace std; typedef long long LL; typedef pair<int,int> PI; typedef vector<int> VI; #define ALL(a) (a).begin(),(a).end() #define PB push_back #define MP make_pair #define FT first #define SD second #define Y first #define X second vector<string>token(string a) { vector<string>w;a.push_back(' '); while(!a.empty()){w.push_back(a.substr(0,a.find(" ")));a=a.substr(a.find(" ")+1,a.size()-1);}return w; } map<string,int> mapik; vector<string> amapik; int dodaj(string a) {if(mapik.count(a)==0) {mapik[a]=mapik.size()-1;amapik.PB(a);}return mapik[a];} const int INF = 1000000000; const LL INFINF = 1000000000000000000LL; PI moves4[4] = { MP(1, 0), MP(-1, 0), MP(0, 1), MP(0, -1) }; PI move(PI st, PI m) { return MP(st.first + m.first, st.second + m.second); } int rows, cols; bool on_board(PI p) { return p.first >= 0 && p.second >= 0 && p.first < rows && p.second < cols; } char tmp_str[1000]; string scanf_string() { scanf("%s",tmp_str); return tmp_str; } inline bool get_bit(int w, int i) { return (w>>i)&1; } // ========================================================== const int N = 200002; int n,m; VI czasy; VI piekarniki; LL brut(int piec) { LL res = 0; int ost_koniec = 0; for (int i = 0; i < n; i++) { LL opoznienie = max(0, piec + ost_koniec - czasy[i]); ost_koniec = czasy[i] + opoznienie; res += opoznienie; } return res; } int main() { scanf("%d%d",&n, &m); for(int i=0;i<n;i++) { int tmp; scanf("%d",&tmp); czasy.push_back(tmp); } int res = 0; for(int i=0;i<m;i++) { int tmp; scanf("%d", &tmp); piekarniki.push_back(tmp); } for (int k = 0; k < m; k++) { LL res = brut(piekarniki[k]); printf("%lld\n", res); } return 0; }
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 | #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <cstdlib> #include <vector> #include <algorithm> #include <cstring> #include <string> #include <map> #include <deque> using namespace std; typedef long long LL; typedef pair<int,int> PI; typedef vector<int> VI; #define ALL(a) (a).begin(),(a).end() #define PB push_back #define MP make_pair #define FT first #define SD second #define Y first #define X second vector<string>token(string a) { vector<string>w;a.push_back(' '); while(!a.empty()){w.push_back(a.substr(0,a.find(" ")));a=a.substr(a.find(" ")+1,a.size()-1);}return w; } map<string,int> mapik; vector<string> amapik; int dodaj(string a) {if(mapik.count(a)==0) {mapik[a]=mapik.size()-1;amapik.PB(a);}return mapik[a];} const int INF = 1000000000; const LL INFINF = 1000000000000000000LL; PI moves4[4] = { MP(1, 0), MP(-1, 0), MP(0, 1), MP(0, -1) }; PI move(PI st, PI m) { return MP(st.first + m.first, st.second + m.second); } int rows, cols; bool on_board(PI p) { return p.first >= 0 && p.second >= 0 && p.first < rows && p.second < cols; } char tmp_str[1000]; string scanf_string() { scanf("%s",tmp_str); return tmp_str; } inline bool get_bit(int w, int i) { return (w>>i)&1; } // ========================================================== const int N = 200002; int n,m; VI czasy; VI piekarniki; LL brut(int piec) { LL res = 0; int ost_koniec = 0; for (int i = 0; i < n; i++) { LL opoznienie = max(0, piec + ost_koniec - czasy[i]); ost_koniec = czasy[i] + opoznienie; res += opoznienie; } return res; } int main() { scanf("%d%d",&n, &m); for(int i=0;i<n;i++) { int tmp; scanf("%d",&tmp); czasy.push_back(tmp); } int res = 0; for(int i=0;i<m;i++) { int tmp; scanf("%d", &tmp); piekarniki.push_back(tmp); } for (int k = 0; k < m; k++) { LL res = brut(piekarniki[k]); printf("%lld\n", res); } return 0; } |