Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- using namespace std;
- int main()
- {
- int n, k;
- cin>>n >> k;
- int m;
- cin>>m;
- if(n > 100) {
- return 0;
- }
- vector<int> req(k + 1, 0);
- vector<int>v;
- for(int i=0; i<n; i++){
- int a;
- cin>>a;
- v.push_back(a);
- }
- int zbir=0;
- for(int j=0; j<m; j++){
- int a, b;
- //a brojot sto go barame // b za kolicina
- cin>>a>>b;
- req[a] = b;
- zbir+=b;
- }
- int min_length=2e9;
- int tmp=0;
- vector<int> t = req;
- for(int i=0; i<v.size(); i++){
- for(int j=0; j<v.size(); j++){
- tmp = 0;
- req = t;
- for(int k=i; k<=j; k++){
- if(req[v[k]]>0){
- req[v[k]]--;
- }
- bool ok = true;
- for(int x = 0; x < req.size(); x++) {
- if(req[x] != 0) {
- ok = false;
- break;
- }
- }
- if(ok) {
- min_length = min(min_length, j - i + 1);
- }
- }
- }
- }
- if(min_length == 2e9) {
- cout << "impossible";
- }
- else
- cout << min_length << endl;
- return 0;
- }
- /*
- 5 2 2
- 0 1 1 0 1
- 0 1
- 1 1
- 13 4 3
- 1 1 3 2 0 1 2 0 0 0 0 3 1
- 0 2
- 2 1
- 1 2
- 5 3 1
- 1 2 0 1 2
- 0 2
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement