#include #include #define rep(i,n) for(int i=0;i vi; typedef vector vl; typedef vector> vvi; typedef vector> vvl; typedef long double ld; typedef pair P; ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const static_modint& a) {os << a.val(); return os;} template istream& operator>>(istream& is, vector& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template ostream& operator<<(ostream& os, const pair& p){os << p.first << ' ' << p.second; return os;} template ostream& operator<<(ostream& os, const vector& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template ostream& operator<<(ostream& os, const vector>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} int main(){ int n, m; cin >> n >> m; vl a(n), b(m), c(n); cin >> a >> b >> c; vl x(n); rep(i, n - 1) x[i + 1] = x[i] + b[i % m]; // cout << x; map ma; rep(i, n) ma[x[i] - a[i]] += c[i]; long long sum = 0; rep(i, n) sum += c[i]; long long ans = 1001001001001001; for(auto [key, value] : ma) ans = min(ans, sum - value); cout << ans << "\n"; return 0; }