QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#236172#3028. Frogsahsoltan#AC ✓664ms43852kbC++202.2kb2023-11-03 17:33:342023-11-03 17:33:34

Judging History

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

  • [2023-11-03 17:33:34]
  • 评测
  • 测评结果:AC
  • 用时:664ms
  • 内存:43852kb
  • [2023-11-03 17:33:34]
  • 提交

answer

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

#define x first
#define y second
#define ir(x,a,b) ((a) <= (x) && (x) <= (b))
#define pb push_back
#define all(x) (x).begin(), (x).end()
/*
#ifdef LOCAL
auto& operator<<(auto&, pair<auto, auto>);
template<typename T, typename = T::value_type>
auto& operator<<(ostream& o, T x) requires (!same_as<T, string>) {
  o << "{";
  string s;
  for (auto i : x) {
    o << s << i;
    s << ", ";
  }
  return o << "}";
}
auto& operator<<(ostream& o, pair<auto, auto> p) {
  return o << "(" << p.first << ", " << p.second << ")";
}
#define debug(x...) cerr << "["#x"]:",[](auto...$){((cerr<<" "<<$),...)<<endl;}(x)
#else
#define debug(...) 2137
#endif
*/


void add(multiset<int>& m, int x) {
	
	if(m.size() < 3) m.insert(x);
	else {
		if(*m.begin() < x) {
			m.erase(m.begin());
			m.insert(x);
		}
	}
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
  
  int t;
  cin >> t;
  while(t--) {
	  int n;
	  cin >> n;
	  vector<int> r(n), s(n);
	  for(int i = 0; i < n; i++) {
		cin >> r[i] >> s[i];
	  }
	  set<pair<int,int>> st;
	  multiset<int, greater<int>> ms;
	  vector<multiset<int>> v(n);
	  for(int i = 0; i < n; i++) {
		while(!st.empty() && st.begin()->first < i) {
			ms.erase(ms.find(s[st.begin()->second]));
			st.erase(st.begin());
		}
		ms.insert(s[i]);
		st.insert({i + r[i], i});
		int cnt = 0;
		for(auto it = ms.begin(); it != ms.end() && cnt < 3; it++) {
			add(v[i], *it);
			cnt++;
		}
	  }
	  ms.clear();
	  set<pair<int,int>, greater<pair<int,int>>> st2;
	  for(int i = n - 1; i >= 0; i--) {
		while(!st2.empty() && st2.begin()->first > i) {
			ms.erase(ms.find(s[st2.begin()->second]));
			st2.erase(st2.begin());
		}
		int cnt = 0;
		for(auto it = ms.begin(); it != ms.end() && cnt < 3; it++) {
			add(v[i], *it);
			cnt++;
		}
		ms.insert(s[i]);
		st2.insert({i - r[i], i});
	  }
	  
	  int ans = 0;
	  for(int i = 0; i < n; i++) {
		if(v[i].size() == 3) {
			int x = 0;
			for(auto it = v[i].begin(); it != v[i].end(); it++) x += *it;
			ans = max(ans, x);
		}
	  }
	  cout << ans <<'\n';
  }
  
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 439ms
memory: 43500kb

input:

29
24946
1 145304
3 52200
2 96731
2 96731
34 5867
5 39209
1 124746
1 195359
1 140091
1 195359
1 140091
2 94760
7 26440
14 14264
34 5735
2 67479
1 116444
4 43152
2 70412
3 54405
3 54405
1 106845
4 49540
1 106845
1 118592
27 7212
1 118592
2 74860
243 821
6 28584
2 74860
1 103054
6 29393
3 55906
2 7299...

output:

596106
213676
571306
288754
4
108
4
8
599840
27
62
539982
46
235651
317587
5
258922
449979
25
165256
12
599968
11
3
5
413196
4
599639
60

result:

ok 29 lines

Test #2:

score: 0
Accepted
time: 664ms
memory: 43852kb

input:

30
3758
62 1
107 1
134 3
133 1
92 1
65 1
276 1
316 1
111 1
274 1
374 2
100 2
217 1
40 1
127 1
123 1
270 2
18 1
26 1
233 2
278 3
152 2
157 2
9 2
61 1
29 1
374 1
45 1
156 1
231 1
303 1
405 1
330 1
407 2
375 3
111 1
269 1
115 1
17 1
56 1
363 1
255 2
176 1
66 3
132 1
35 2
391 1
371 2
260 1
175 1
369 4
7...

output:

15
111
570316
6
145
598141
9790
379220
6
302651
8977
7187
574039
276501
528609
1189
6
416728
20557
9
20919
9
524338
266777
500921
559918
62
10635
3609
521671

result:

ok 30 lines

Test #3:

score: 0
Accepted
time: 348ms
memory: 37112kb

input:

30
16
3 9
7 18
3 20
8 2
5 9
6 1
2 19
2 6
3 22
2 8
7 11
3 9
1 12
2 6
8 11
7 7
16
13 2
2 2
13 2
12 4
3 4
2 3
2 3
1 3
1 3
11 1
1 3
4 3
11 4
7 2
7 5
7 4
166437
1 182681
1 170305
1 130895
2 81506
1 121104
2 99552
1 134739
1 180951
2 82208
2 86256
1 189082
3 53511
1 172928
6 32142
2 88879
1 136048
1 13239...

output:

61
13
589248
5
565958
296385
3
42
83
419938
25
541769
569373
12
385323
3
24
410656
579080
4
63
15
317025
6
246039
310300
133
239965
335677
12

result:

ok 30 lines