Subsequence Weighting
2016-07-21 23:21
309 查看
题目链接
#include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <vector> #include <set> #include <map> #include <iostream> #include <algorithm> using namespace std; typedef long long ll; const int maxn = 100010; const ll inf = 0x3f3f3f3f3f3f3f3fLL; map<int, ll> mp; int a[maxn], b[maxn]; ll max(ll a, ll b) { return a > b ? a : b; } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int T, n; ll ans, tmp; map<int, ll>::iterator it1, it2; scanf("%d", &T); while(T--) { scanf("%d", &n); for(int i = 0; i < n; ++i) { scanf("%d", &a[i]); } for(int i = 0; i < n; ++i) { scanf("%d", &b[i]); } mp.clear(); ans = b[0]; mp[a[0]] = b[0]; for(int i = 1; i < n; ++i) { if(mp.lower_bound(a[i]) == mp.begin()) { mp[a[i]] = max(mp[a[i]], (ll)b[i]); } else { it1 = mp.lower_bound(a[i]); it1--; mp[a[i]] = max(mp[a[i]], it1->second + b[i]); } ans = max(ans, mp[a[i]]); tmp = mp[a[i]]; it1 = mp.find(a[i]); it2 = ++it1; while(it2 != mp.end()) { if(it2->second <= tmp) { mp.erase(it2); it1 = mp.find(a[i]); it2 = ++it1; } else { break; } } } cout << ans << endl; } return 0; }
相关文章推荐
- ACM--学生排队--HDOJ 1297--Children’s Queue--大数
- iOS开发小技巧--即时通讯项目:消息发送框(UITextView)高度的变化; 以及UITextView光标复位的小技巧
- MySQL数据库中QueryCache的锁模型
- LeetCode Guess Number Higher or Lower
- 8.0 UISearchController 改变 searchBar 的取消按钮
- 工作情感2-关于UE总监的一些思考
- iOS开发小技巧--即时通讯项目:使用富文本在UILabel中显示图片和文字;使用富文本占位显示图片
- iOS开发从入门到精通-- 单行文本UITextField
- GUI 事件处理
- GUI:图形用户界面 界面设计
- $(" ").value的意思
- Java StringBuffe与StringBuilderr的浅谈
- CodeForces 689D Friends and Subsequences (RMQ+二分)
- LeetCode - 303. Range Sum Query - Immutable
- UI重要还是创新重要
- Codeforces Round #304 (Div. 2) C queue暴力
- String、String.valueOf、toString 它们三者的区别总结
- Leetcode Unique Paths
- The True Cost of Calls
- 关于UIButton 在autolayout中应用中的一个问题