結果

問題 No.2566 美しい整数列
ユーザー ゆにぽけゆにぽけ
提出日時 2023-12-02 16:23:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 1,925 bytes
コンパイル時間 1,670 ms
コンパイル使用メモリ 139,924 KB
実行使用メモリ 20,608 KB
最終ジャッジ日時 2023-12-02 16:24:02
合計ジャッジ時間 5,739 ms
ジャッジサーバーID
(参考情報)
judge9 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 129 ms
20,608 KB
testcase_05 AC 130 ms
20,608 KB
testcase_06 AC 61 ms
8,064 KB
testcase_07 AC 63 ms
8,064 KB
testcase_08 AC 60 ms
8,064 KB
testcase_09 AC 63 ms
8,064 KB
testcase_10 AC 71 ms
8,064 KB
testcase_11 AC 87 ms
11,136 KB
testcase_12 AC 82 ms
11,136 KB
testcase_13 AC 85 ms
11,136 KB
testcase_14 AC 85 ms
11,136 KB
testcase_15 AC 87 ms
11,136 KB
testcase_16 AC 112 ms
19,712 KB
testcase_17 AC 120 ms
19,968 KB
testcase_18 AC 124 ms
20,096 KB
testcase_19 AC 81 ms
14,464 KB
testcase_20 AC 111 ms
18,816 KB
testcase_21 AC 138 ms
19,200 KB
testcase_22 AC 78 ms
13,440 KB
testcase_23 AC 95 ms
17,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cassert>
#include<cmath>
#include<ctime>
#include<iomanip>
#include<numeric>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<random>
#include<functional>
#include<utility>
using namespace std;

#include<algorithm>
#include<vector>
#include<cassert>
using namespace std;
struct UnionFind
{
	private:
	int n;
	vector<int> par,siz;

	public:
	UnionFind(int n) :n(n),par(n,-1),siz(n,1) {}

	int root(int u) 
	{
		assert(0 <= u && u < n);
		return (par[u] < 0 ? u:par[u] = root(par[u]));
	}

	bool same(int u,int v)
	{
		assert(0 <= u && u < n && 0 <= v && v < n);
		return root(u) == root(v);
	}

	bool unite(int u,int v)
	{
		assert(0 <= u && u < n && 0 <= v && v < n);
		u = root(u),v = root(v);
		if(u == v) return false;

		if(siz[u] < siz[v]) swap(u,v);

		siz[u] += siz[v];
		par[v] = u;

		return true;
	}

	int size(int u)
	{
		assert(0 <= u && u < n);
		return siz[root(u)];
	}

	vector<vector<int>> components()
	{
		vector<vector<int>> ret(n);
		for(int u = 0;u < n;u++) ret[root(u)].push_back(u);

		ret.erase(remove_if(ret.begin(),ret.end(),[](vector<int> v) { return v.empty();}),ret.end());

		return ret;
	}
};

void solve()
{
	int N,M;
	cin >> N >> M;
	vector<long long> A(N),B(M),C(N);
	for(int i = 0;i < N;i++) cin >> A[i];
	for(int i = 0;i < M;i++) cin >> B[i];
	for(int i = 0;i < N;i++) cin >> C[i];
	long long S = 0;
	for(int i = 0;i < N;i++)
	{
		A[i] -= S;
		S += B[i%M];
	}
	map<long long,long long> mp;
	long long ans = 0;
	for(int i = 0;i < N;i++)
	{
		mp[A[i]] += C[i];
		ans += C[i];
	}
	long long mx = 0;
	for(auto it = mp.begin();it != mp.end();it++) mx = max(mx,it->second);
	ans -= mx;
	cout << ans << endl;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	/* cin >> tt; */
	while(tt--) solve();
}
0