Submission #1120031

#TimeUsernameProblemLanguageResultExecution timeMemory
1120031kirakosyanSchools (IZhO13_school)C++17
15 / 100
2087 ms5848 KiB
#include<algorithm> #include<iostream> #include<vector> #include<string> #include<random> #include<cmath> #include<stack> #include<map> #include <iomanip> #include <queue> #include <set> using namespace std; using ll = long long; using ull = unsigned long long; ll mod = 1e9 + 7; ll pv(ll a, ll b) { if (b == 0)return 1; ll res = (pv(a, b / 2)); if (b % 2) { return (((res * res) % mod) * (a % mod)) % mod; } else { return (res * res) % mod; } } vector<ll>a, b; vector<vector<ll>>gp; ll f = 0; const ll N = 1e7 + 5; // dp=vector<ll>(max(sum,(1ll<<m))+5); void solve() { int n, m, s; cin >> n >> m >> s; vector<int>v(n), a(n); for (int i = 0; i < n; i++) { cin >> v[i] >> a[i]; } ll mx = 0; for (int i = 1; i < (1 << n); i++){ vector<int>a1, v1; for (int j = 0; j < n; j++) { if (i & (1 << j)) { //sum += a[j]; //vis[j] = 1; v1.push_back(v[j]); } else a1.push_back(a[j]); } sort(v1.rbegin(), v1.rend()); sort(a1.rbegin(), a1.rend()); ll sum = 0; for (int j = 0; j < min(m,int(v1.size())); j++) { sum += v1[j]; } for (int j = 0; j < min(s,int(a1.size())); j++) { sum += a1[j]; } mx = max(mx, sum); } for (int i = 1; i < (1 << n); i++) { vector<int>a1, v1; for (int j = 0; j < n; j++) { if ((i & (1 << j))==0) { //sum += a[j]; //vis[j] = 1; v1.push_back(v[j]); } else a1.push_back(a[j]); } sort(v1.rbegin(), v1.rend()); sort(a1.rbegin(), a1.rend()); ll sum = 0; for (int j = 0; j < min(m, int(v1.size())); j++) { sum += v1[j]; } for (int j = 0; j < min(s, int(a1.size())); j++) { sum += a1[j]; } mx = max(mx, sum); } cout << mx << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin.tie(nullptr); ll _ = 1; // cin >> _; while (_--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...