#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int k;
ll n, x, t;
int main()
{
cin >> k;
while(k --)
{
ll res = 0;
cin >> n >> x >> t;
ll cnt = t / x;
if(cnt >= n - 1)
res = n * (n-1) / 2;
else
{
ll num = n - cnt;
res = num * cnt + cnt * (cnt-1) / 2;
}
cout << res << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
int n, q;
char str[N];
ll sum[N];
int main()
{
cin >> n >> q;
cin >> str + 1;
for(int i = 1; i <= n; i++)
sum[i] += sum[i-1] + (ll)(str[i] - ‘a‘) + (ll)1;
while(q --)
{
int l, r;
cin >> l >> r;
cout << sum[r] - sum[l-1] << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
ll num[N] ,a[N];
ll n, k, x;
int cnt = 0;
int main()
{
cin >> n >> k >> x;
for(int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + 1 + n);
if(n == 1) cout << 1 << endl;
else
{
for(int i = 2; i <= n; i++)
{
ll dis = a[i] - a[i-1];
if(dis > x)
num[++cnt] = (dis + x - 1) / x - 1;
}
sort(num + 1, num + cnt + 1);
int tcnt = cnt;
for(int i = 1; i <= tcnt && k >= num[i]; i++)
{
k -= num[i];
cnt --;
}
cout << cnt + 1<< endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
int n;
struct P
{
ll a, b;
}p[N];
bool cmp(P x, P y)
{
return x.b < y.b;
}
int main()
{
ll sum = 0, cnt = 0; //总花费、当前已购买商品的数量
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> p[i].a >> p[i].b;
sum += p[i].a * (ll)2;
}
sort(p + 1, p + 1 + n, cmp);
int l = 1, r = n;
while(l <= r)
{
if(cnt >= p[l].b) //当前商品所需数量达到打折的数量
{
cnt += p[l].a;
sum -= p[l].a; //打折的商品数量
l ++;
}
else
{
if(p[r].a + cnt >= p[l].b)
{
p[r].a -= p[l].b - cnt;
cnt = p[l].b;
}
else //加上第r种商品仍不满足第l种商品能打折
{
cnt += p[r].a;
r --;
}
}
}
cout << sum << endl;
return 0;
}
Codeforces Round #727 (Div. 2) A~D
原文:https://www.cnblogs.com/K2MnO4/p/14946373.html