#include <cstdio> using namespace std; long long int times[200002]; long long int furnance[200002]; long long int delta[200002]; long long int results[200002]; long long int wasteOfTime = 0; void print(long long int arr[], int n) { for(int i = 0; i < n; i++) { printf("%lld ", arr[i]); } printf("\n"); } void count(long long int arr[], int n) { for(int i = 0; i < n ; i++) { if(arr[i] < 0) wasteOfTime -= arr[i]; } } int main() { int n,m; scanf("%d", &n); scanf("%d", &m); for(int i = 0; i < n ; i++) { scanf("%lld", ×[i]); } for(int i = 0; i < m; i++) { scanf("%lld", &furnance[i]); } delta[0] = times[0]; for(int i = 1; i < n; i++) { delta[i] = times[i] - times[i-1]; } for(int i = 0; i < m; i++) { results[0] = delta[0] - furnance[i]; for(int j = 1; j < n; j++) { results[j] = delta[j] - furnance[i]; if(results[j-1] < 0) { results[j] += results[j-1]; } } for(int i = 0; i < n ; i++) { if(results[i] < 0) wasteOfTime -= results[i]; } printf("%lld\n", wasteOfTime); wasteOfTime = 0; } 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 | #include <cstdio> using namespace std; long long int times[200002]; long long int furnance[200002]; long long int delta[200002]; long long int results[200002]; long long int wasteOfTime = 0; void print(long long int arr[], int n) { for(int i = 0; i < n; i++) { printf("%lld ", arr[i]); } printf("\n"); } void count(long long int arr[], int n) { for(int i = 0; i < n ; i++) { if(arr[i] < 0) wasteOfTime -= arr[i]; } } int main() { int n,m; scanf("%d", &n); scanf("%d", &m); for(int i = 0; i < n ; i++) { scanf("%lld", ×[i]); } for(int i = 0; i < m; i++) { scanf("%lld", &furnance[i]); } delta[0] = times[0]; for(int i = 1; i < n; i++) { delta[i] = times[i] - times[i-1]; } for(int i = 0; i < m; i++) { results[0] = delta[0] - furnance[i]; for(int j = 1; j < n; j++) { results[j] = delta[j] - furnance[i]; if(results[j-1] < 0) { results[j] += results[j-1]; } } for(int i = 0; i < n ; i++) { if(results[i] < 0) wasteOfTime -= results[i]; } printf("%lld\n", wasteOfTime); wasteOfTime = 0; } return 0; } |