QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#345241#3412. Battle for SilverPetroTarnavskyi#AC ✓2ms3840kbC++201.2kb2024-03-06 17:14:552024-03-06 17:14:56

Judging History

你现在查看的是最新测评结果

  • [2024-03-06 17:14:56]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:3840kb
  • [2024-03-06 17:14:55]
  • 提交

answer

#include <bits/stdc++.h> 

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int N = 474;

int n, m;
bool g[N][N];

void solve()
{
	VI s(n);
	for (int& si : s)
		cin >> si;
	FOR(i, 0, n)
		FOR(j, 0, n)
			g[i][j] = false;
	FOR(i, 0, m)
	{
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		g[u][v] = g[v][u] = true;
	}
	int ans = 0;
	FOR(v1, 0, n)
	{
		FOR(v2, v1 + 1, n)
		{
			if (!g[v1][v2])
				continue;
			ans = max(ans, s[v1] + s[v2]);
			FOR(v3, v2 + 1, n)
			{
				if (!g[v1][v3] || !g[v2][v3])
					continue;
				ans = max(ans, s[v1] + s[v2] + s[v3]);
				FOR(v4, v3 + 1, n)
				{
					if (!g[v1][v4] || !g[v2][v4] || !g[v3][v4])
						continue;
					ans = max(ans, s[v1] + s[v2] + s[v3] + s[v4]);
				}
			}
		}
	}
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	while (cin >> n >> m)
		solve();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3808kb

input:

409 412
4459
2527
1895
3518
4470
1757
3066
4342
5464
2770
263
1283
3338
147
1789
5977
1982
3528
5675
2655
4942
2408
2977
4480
463
2066
605
2926
5492
1230
4318
1166
5332
4581
408
1098
737
1018
282
5064
275
4106
2469
2598
5355
1711
4302
5581
2592
2099
2066
887
5890
2905
1204
2151
5550
3415
3154
2503
1...

output:

11630
10270
10970
11669
10536
13247
10400
10390
11486
10465
10850
11225
10214
12309
10839
11667
10468
11876
8860
10987
10426
11845
11714
11097
11572
11517
11627
11225
11141
11771
11569
11857
11838
11814
16329
8663
10565
15577
15196
9573
17897
15082
13049
12288
13246
18645
11469
11237
20095
15975
151...

result:

ok 982 lines

Test #2:

score: 0
Accepted
time: 2ms
memory: 3744kb

input:

450 449
100
113
126
139
152
165
178
191
204
217
230
243
256
269
282
295
308
321
334
347
360
373
386
399
412
425
438
451
464
477
490
503
516
529
542
555
568
581
594
607
620
633
646
659
672
685
698
711
724
737
750
763
776
789
802
815
828
841
854
867
880
893
906
919
932
945
958
971
984
997
1010
1023
10...

output:

11861
23592
16700
6435
17580
20594
17465

result:

ok 7 lines

Test #3:

score: 0
Accepted
time: 1ms
memory: 3836kb

input:

2 1
100
5000
1 2
3 3
100
5000
1000
1 2
1 3
2 3
5 9
100
5000
1000
2000
200
1 2
1 3
1 4
2 3
2 4
3 4
1 5
4 5
2 5
6 10
100
200
300
400
500
600
1 2
1 3
1 4
1 5
2 3
4 5
5 6
3 6
2 5
3 5
3 2
100
100
100
1 2
2 3
4 4
1000
1000
100
500
1 2
2 3
2 4
3 4
5 6
1000
2000
3000
4000
5000
1 2
1 3
2 3
3 4
3 5
4 5
5 7
60...

output:

5100
6100
8100
1400
200
2000
12000
12000
18000

result:

ok 9 lines

Test #4:

score: 0
Accepted
time: 2ms
memory: 3680kb

input:

300 894
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
...

output:

400
18128
18569
19602
8520
8935

result:

ok 6 lines

Test #5:

score: 0
Accepted
time: 1ms
memory: 3728kb

input:

300 299
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
10...

output:

2000

result:

ok single line: '2000'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

4 6
100
5000
1000
2000
1 2
1 3
1 4
2 3
2 4
3 4
6 8
1500
1000
100
2000
500
300
1 2
1 3
1 4
2 4
3 5
4 5
4 6
5 6

output:

8100
4500

result:

ok 2 lines