• API
• FAQ
• Tools
• Archive
SHARE
TWEET # [codeforces] School Marks C++ solution mraron  May 1st, 2015 (edited) 270 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include<bits/stdc++.h>
2. using namespace std;
3.
4. int main()
5. {
6.     int n,k,p,x,y;
7.     cin >> n >> k >> p >> x >> y; //reading
8.     int goods=0,sum=0;            //goods: number of ai's, where ai>=y    sum: sum of ai's
9.     vector<int> a; a.reserve(n);  //the given tests
10.     for(int i=0;i<k;++i)
11.     {
12.         int ai;            //the current test
14.         a.push_back(ai);   //adding into the vector
15.         sum+=ai;           //...
16.         if(y<=ai) goods++; //...
17.     }
18.     vector<int> ans;       //the vector, where we hold our answers
19.     while(goods<(n-goods)) //In the Editorial, the first condition
20.     {
21.         ans.push_back(y);
22.         goods++;
23.         sum+=y;
24.     }
25.     if( ans.size()+a.size()>n ) //If we have to write more than n tests to satisfy the condtition, then we're wrong.
26.     {
27.         cout << "-1\n";
28.         return 0;
29.     }
30.     while(ans.size()+a.size()<n) //First condition: ok, then fill the remaining space with ones.
31.     {
32.         ans.push_back(1);
33.         sum++;
34.     }
35.     if( sum > x ) //Second Condition
36.     {
37.         cout << "-1\n";
38.         return 0;
39.     }
40.     for(auto i:ans) //Simply print the answer to the problem
41.     {
42.         cout << i << " ";
43.     }
44.     cout << "\n";
45.
46.
47.     return 0;
48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?