Advertisement
shawon_majid

CF 1901A

Nov 25th, 2023
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | Source Code | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main(void){
  4.     int t, n, x, *arr, arr2[1050], i, j;
  5.     scanf("%d", &t);
  6.     for(i = 0; i < t; i++){
  7.         scanf("%d", &n);
  8.         scanf("%d", &x);
  9.         arr = (int *) malloc(sizeof(int) * (n + 2));
  10.         arr[0] = 0;
  11.         for(j = 1; j <= n; j++){
  12.             scanf("%d", &arr[j]);
  13.         }
  14.  
  15.         arr[j] = arr[j - 1] + (2 * (x - arr[j - 1]));
  16.  
  17.         int d = 0;      
  18.  
  19.         for(j = 1; j <= n + 1; j++){
  20.             if((arr[j] - arr[j - 1]) > d){
  21.                 d = arr[j] - arr[j - 1];
  22.             }    
  23.         }
  24.         printf("%d\n", d);
  25.     }
  26.  
  27.     free(arr);
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement