#include <bits/stdc++.h> #define int long long using namespace std; int t[200005],zap[200005],s[200005],n,m; int slow(int x) { int akt=0,res=0; int pocz=0; for(int i=1;i<=n;i++) { pocz=max(akt,t[i]-x); res+=max(0LL,pocz+x-t[i]); akt=pocz+x; } return res; } int R(int a,int b) { return rand()%(b-a+1)+a; } main() { ios_base::sync_with_stdio(0); cin >> n >> m; for(int i=1;i<=n;i++)cin >> t[i]; while(m--)cin >> zap[m],cout << slow(zap[m])<<"\n"; }
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 | #include <bits/stdc++.h> #define int long long using namespace std; int t[200005],zap[200005],s[200005],n,m; int slow(int x) { int akt=0,res=0; int pocz=0; for(int i=1;i<=n;i++) { pocz=max(akt,t[i]-x); res+=max(0LL,pocz+x-t[i]); akt=pocz+x; } return res; } int R(int a,int b) { return rand()%(b-a+1)+a; } main() { ios_base::sync_with_stdio(0); cin >> n >> m; for(int i=1;i<=n;i++)cin >> t[i]; while(m--)cin >> zap[m],cout << slow(zap[m])<<"\n"; } |