【求助】 P2949

P2949 [USACO09OPEN] Work Scheduling G

```cpp``` #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cmath> #include<map> #include<queue> using std::cin; using std::cout; using std::sort; using std::endl; using std::priority_queue; using std::min; using std::max; const int maxn = 2000000 + 10; typedef long long ll; struct m { ll d , p; } a[maxn]; ll n; ll ans; priority_queue<ll> q; bool cmp(m x , m y) { return (x.d > y.d); } int main() { //freopen("testdata.in","r",stdin); cin>>n; for(int i = 1 ; i <= n ; i ++) { scanf("%lld%lld",&a[i].d,&a[i].p); } sort(a + 1 , a + n + 1 , cmp); ll h = 0; int now = 1; while(now <= n) { int next = now; while(a[next].d == a[now].d) { q.push(a[next].p); next ++; } h += max(min(a[now].d , (ll)100000000) - a[next].d, 0LL); //h += a[now].d - a[next].d; while((h > 0LL) && (q.empty() == false)) { ans += q.top(); q.pop(); h --; } now = next; } printf("%lld\n",ans); } ```
by Jzw_2001 @ 2018-04-18 10:26:27


```cpp``` #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cmath> #include<map> #include<queue> using std::cin; using std::cout; using std::sort; using std::endl; using std::priority_queue; using std::min; using std::max; const int maxn = 2000000 + 10; typedef long long ll; struct m { ll d , p; } a[maxn]; ll n; ll ans; priority_queue<ll> q; bool cmp(m x , m y) { return (x.d > y.d); } int main() { cin>>n; for(int i = 1 ; i <= n ; i ++) { scanf("%lld%lld",&a[i].d,&a[i].p); } sort(a + 1 , a + n + 1 , cmp); ll h = 0; int now = 1; while(now <= n) { int next = now; while(a[next].d == a[now].d) { q.push(a[next].p); next ++; } h += max(min(a[now].d , (ll)100000000) - a[next].d, 0LL); while((h > 0LL) && (q.empty() == false)) { ans += q.top(); q.pop(); h --; } now = next; } printf("%lld\n",ans); } ```
by Jzw_2001 @ 2018-04-18 10:27:28


这markdown为啥不好用??
by Jzw_2001 @ 2018-04-18 10:27:53


markdown使用: 代码粘贴: \`\`\`cpp //此处是代码 \`\`\` 这里我使用了markdown转义字符使得字符以原样呈现,同时看到luogu官方发的markdown教程,不会用转义字符那教程实在是太丑了,希望更正。
by constructor @ 2018-04-18 16:58:02


@[kkksc03](/space/show?uid=1)
by constructor @ 2018-04-18 17:02:06


@[constructor](/space/show?uid=56461) 第一行的cpp后,不要加3撇
by kkksc03 @ 2018-04-18 17:04:37


@[kkksc03](/space/show?uid=1) 什么意思?哪里有问题?
by constructor @ 2018-04-18 17:07:27


@[kkksc03](/space/show?uid=1) 还有问下markdown代码插入不是正统规定的,SO上面是四个空格来着……是这样的吗?
by constructor @ 2018-04-18 17:08:34


|