/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 332.0 KiB
#2 Wrong Answer 2ms 328.0 KiB
#3 Wrong Answer 29ms 580.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
#define ll long long

void solve() {
	int n, m; cin >> n >> m;
	vector<int> v;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			int x; cin >> x;
			v.push_back(x);
		}
	}
	sort(v.begin(), v.end());
	deque <int> q(v.begin(), v.end());
	int ans[n][m];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			int ds = i + j;
			if (ds % 2 == 0) {
				ans[i][i] = q.front();
				q.pop_front();
			}
			else {
				ans[i][j] = q.back();
				q.pop_back();
			}
		}
	}
	int a = 1e9;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (i + 1 < n) a = min(a, ans[i + 1][j] + ans[i][j]);
			if (j + 1 < m) a = min(a, ans[i][j + 1] + ans[i][j]);
		}
	}
	cout << a << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int tt = 1;
	cin >> tt;
	while (tt--) {
		solve();
	}
}

Information

Submit By
Type
Submission
Problem
P1065 Matrix Sum
Contest
Brain Booster #4
Language
C++20 (G++ 13.2.0)
Submit At
2024-07-14 17:38:00
Judged At
2024-11-11 03:22:48
Judged By
Score
5
Total Time
29ms
Peak Memory
580.0 KiB