CodeForce 580D Kefa and Company贪心算法
来源:互联网 发布:python与数据挖掘书籍 编辑:程序博客网 时间:2024/05/15 11:43
从网上看到的方法,结合自己理解写出,确实值得学。
#include <cstdio>#include <utility>#include <cstring>#include <algorithm>using namespace std;const int maxn = 1e5 + 10;int main(){int n, d;while (scanf("%d%d", &n, &d) != EOF){pair<int, int>a[maxn];for (int i = 0; i < n; i++){int x, y;scanf("%d%d", &x, &y);a[i].first = x;a[i].second = y;}sort(a, a + n);__int64 ans = 0, cur = 0, st = 0;for (int i = 0; i < n;){if (a[i].first - a[st].first >= d){cur -= a[st].second;st++;}else{cur += a[i].second;i++;}ans = max(ans, cur);}printf("%I64d\n", ans);}return 0;}
0 0
- CodeForce 580D Kefa and Company贪心算法
- codeforce B Kefa and Company
- CodeForces 580B Kefa and Company <贪心>
- CF#321-B - Kefa and Company-贪心-
- coderforce 580B Kefa and Company
- codeforces-580B Kefa and Company(二分)
- CodeForces 580B Kefa and Company
- Codeforces 580B Kefa and Company
- 【CodeForces】[580B]Kefa and Company
- CodeForces 580B Kefa and Company
- CodeForces 580B Kefa and Company
- 【CodeForces 580B】Kefa and Company
- codeforces 580B Kefa and Company
- Kefa and Company
- B. Kefa and Company
- Kefa and Company
- L - Kefa and Company
- Kefa and Company
- The requested resource (/) is not available
- 采集转码以及模拟浏览器访问
- Apache Maven 入门篇
- “我是集美貌与才华于一身的PAPI酱”,她为什么可以融到1200万
- POJ 3624 Charm Bracelet
- CodeForce 580D Kefa and Company贪心算法
- Nim Game
- LeetCode(java)5. Longest Palindromic Substring
- 2016.4.10Python列表生成式及生成器generator
- 【AR】参加HACKPKU的AR初体验
- Android ServiceConnection详解
- 谷歌开源机器学习,这个狂拽炫酷吊炸天的技术究竟是什么玩意?
- 20160410】嗯……省选两日游完了抒发一下感想 (讲道理这里可以抒情?【SCOI2016
- Educational Codeforces Round 11--A. Co-prime Array