ログイン
新規登録
AtsuoCoder Petrozavodsk Contest 001
読込中…
Home
Tasks
Clar
Submissions
Standings
提出 ac2da673-c921-4cf7-ac9b-33cee6edaef8
コード
#include <iostream> #include <unordered_map> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, M; cin >> N >> M; vector<int> I(M), S(M); for (int i = 0; i < M; i++) cin >> I[i]; for (int i = 0; i < M; i++) cin >> S[i]; unordered_map<int, int> cnt; int l = 0, r = 0, types = 0; long long sum = 0; long long min_sum = LLONG_MAX; int ansL = -1, ansR = -1; while (r < M) { if (cnt[I[r]] == 0) types++; cnt[I[r]]++; sum += S[r]; r++; while (types >= N) { if (types == N) { if (sum < min_sum) { min_sum = sum; ansL = l; ansR = r; } } cnt[I[l]]--; sum -= S[l]; if (cnt[I[l]] == 0) types--; l++; } } if (ansL == -1) { cout << "-1 -1\n"; } else { cout << ansL+1 << " " << ansR+1<< "\n"; } return 0; }
結果
問題
点数
言語
結果
実行時間
メモリ
F. Sliding
0
C++ (gcc)
IE
0 ms
0 KiB