ログイン
新規登録
AtsuoCoder Petrozavodsk Contest 001
読込中…
Home
Tasks
Clar
Submissions
Standings
提出 d4838896-aabf-4a9f-9754-5c15f00d5a6a
コード
#include <iostream> #include <vector> #include <unordered_map> #include <climits> 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
150
C++
AC
88 ms
15372 KiB