ログイン
新規登録
AtsuoCoder Petrozavodsk Contest 001
読込中…
Home
Tasks
Clar
Submissions
Standings
提出 3deeedf4-99d6-4af9-8e5d-c477ae474d0b
コード
#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++
WJ
0 ms
0 KiB
コンパイルエラー
Main.cpp: In function 'int main()': Main.cpp:12:5: error: 'vector' was not declared in this scope 12 | vector<int> I(M), S(M); | ^~~~~~ Main.cpp:4:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'? 3 | #include <unordered_map> +++ |+#include <vector> 4 | using namespace std; Main.cpp:12:12: error: expected primary-expression before 'int' 12 | vector<int> I(M), S(M); | ^~~ Main.cpp:13:40: error: 'I' was not declared in this scope 13 | for (int i = 0; i < M; i++) cin >> I[i]; | ^ Main.cpp:14:40: error: 'S' was not declared in this scope 14 | for (int i = 0; i < M; i++) cin >> S[i]; | ^ Main.cpp:19:25: error: 'LLONG_MAX' was not declared in this scope 19 | long long min_sum = LLONG_MAX; | ^~~~~~~~~ Main.cpp:4:1: note: 'LLONG_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'? 3 | #include <unordered_map> +++ |+#include <climits> 4 | using namespace std; Main.cpp:23:17: error: 'I' was not declared in this scope 23 | if (cnt[I[r]] == 0) types++; | ^ Main.cpp:24:13: error: 'I' was not declared in this scope 24 | cnt[I[r]]++; | ^ Main.cpp:25:16: error: 'S' was not declared in this scope 25 | sum += S[r]; | ^