Submission #756390

# Submission time Handle Problem Language Result Execution time Memory
756390 2023-06-11T16:33:40 Z Olympia Schools (IZhO13_school) C++17
15 / 100
2000 ms 9868 KB
#include <vector>
#include <iostream>
#include <cassert>
#include <random>
#include <cmath>
#include <map>
#include <algorithm>
#include <bitset>
#include <queue>
#include <set>
#include <stack>
using namespace std;
vector<pair<int64_t,int64_t>> music, sports;
vector<pair<int64_t,int64_t>> vec;
int64_t val () {
	int64_t ans = 0;
	for (int i = 0; i < music.size(); i++) {
		ans += music[i].first;
	}
	for (int i = 0; i < sports.size(); i++) {
		ans += sports[i].second;
	}
	return ans;
}
bool comp (pair<int64_t, int64_t> p1, pair<int64_t, int64_t> p2) {
	return (p1.first + p2.first < p1.second + p2.second);
}
int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, M, S;
    cin >> N >> M >> S;
    vec.resize(N);
    for (int i = 0; i < N; i++) {
    	cin >> vec[i].first >> vec[i].second;
    }
    sort(vec.begin(), vec.end(), comp);
    //reverse(vec.begin(), vec.end());
    for (auto& value: vec) {
    	if (music.size() < M or sports.size() < S) {
    		if (music.size() < M) {
    			music.push_back(value);
    		} else if (sports.size() < S) {
    			sports.push_back(value);
    		}
    	} else {
    		int64_t mx = 0;
    		for (int i = 0; i < music.size(); i++) {
    			auto m = music[i];
    			music[i] = value;
    			mx = max(mx, val());
    			music[i] = m;
    		}
    		for (int i = 0; i < sports.size(); i++) {
    			auto s = sports[i];
    			sports[i] = value;
    			mx = max(mx, val());
    			sports[i] = s;
    		}
    		if (mx < val()) {
    			continue;
    		}
    		for (int i = 0; i < music.size(); i++) {
    			auto m = music[i];
    			music[i] = value;
    			if (val() == mx) {
    				continue;
    			}
    			music[i] = m;
    		}
    		for (int i = 0; i < sports.size(); i++) {
    			auto s = sports[i];
    			sports[i] = value;
    			if (val() == mx) {
    				continue;
    			}
    			sports[i] = s;
    		}
    	}
    	for (int i = 0; i < music.size(); i++) {
    		for (int j = 0; j < sports.size(); j++) {
    			int64_t orig_val = val();
    			swap(music[i], sports[j]);
    			int64_t new_val = val();
    			if (new_val < orig_val) {
    				swap(music[i], sports[j]);
    			}
    		}
    	}
    }
    cout << val();
}

Compilation message

school.cpp: In function 'int64_t val()':
school.cpp:17:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long int, long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |  for (int i = 0; i < music.size(); i++) {
      |                  ~~^~~~~~~~~~~~~~
school.cpp:20:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long int, long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for (int i = 0; i < sports.size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~
school.cpp: In function 'int main()':
school.cpp:40:23: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long int, long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   40 |      if (music.size() < M or sports.size() < S) {
      |          ~~~~~~~~~~~~~^~~
school.cpp:40:44: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long int, long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   40 |      if (music.size() < M or sports.size() < S) {
      |                              ~~~~~~~~~~~~~~^~~
school.cpp:41:24: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long int, long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   41 |       if (music.size() < M) {
      |           ~~~~~~~~~~~~~^~~
school.cpp:43:32: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long int, long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   43 |       } else if (sports.size() < S) {
      |                  ~~~~~~~~~~~~~~^~~
school.cpp:48:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long int, long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |       for (int i = 0; i < music.size(); i++) {
      |                       ~~^~~~~~~~~~~~~~
school.cpp:54:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long int, long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |       for (int i = 0; i < sports.size(); i++) {
      |                       ~~^~~~~~~~~~~~~~~
school.cpp:63:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long int, long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |       for (int i = 0; i < music.size(); i++) {
      |                       ~~^~~~~~~~~~~~~~
school.cpp:71:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long int, long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |       for (int i = 0; i < sports.size(); i++) {
      |                       ~~^~~~~~~~~~~~~~~
school.cpp:80:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long int, long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |      for (int i = 0; i < music.size(); i++) {
      |                      ~~^~~~~~~~~~~~~~
school.cpp:81:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long int, long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |       for (int j = 0; j < sports.size(); j++) {
      |                       ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 7 ms 280 KB Output isn't correct
5 Runtime error 1 ms 596 KB Execution killed with signal 6
6 Runtime error 59 ms 532 KB Execution killed with signal 6
7 Runtime error 2 ms 596 KB Execution killed with signal 11
8 Execution timed out 2081 ms 596 KB Time limit exceeded
9 Runtime error 1 ms 596 KB Execution killed with signal 11
10 Execution timed out 2064 ms 604 KB Time limit exceeded
11 Execution timed out 2080 ms 468 KB Time limit exceeded
12 Runtime error 2 ms 596 KB Execution killed with signal 11
13 Runtime error 13 ms 1620 KB Execution killed with signal 11
14 Runtime error 15 ms 2900 KB Execution killed with signal 11
15 Runtime error 32 ms 5492 KB Execution killed with signal 11
16 Runtime error 34 ms 6120 KB Execution killed with signal 11
17 Runtime error 63 ms 7332 KB Execution killed with signal 11
18 Runtime error 40 ms 8048 KB Execution killed with signal 11
19 Runtime error 69 ms 8608 KB Execution killed with signal 11
20 Runtime error 51 ms 9868 KB Execution killed with signal 11